Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty haddocks and remove empty comments. #1459

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check empty block haddocks separately
  • Loading branch information
philderbeast committed Aug 4, 2024
commit 3328bf23981e840521cf27a88b15014a42604d80
19 changes: 13 additions & 6 deletions src/Hint/Comment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ commentHint _ m =
traceShow ("runs", fmap commentText <$> runs) $
traceShow ("lineHaddocks", commentText <$> lineHaddocks) $
traceShow ("lines", commentText <$> lines) $
if any fst runReplacements
then concatMap snd runReplacements
else concatMap (check singleLines someLines) comments
blockHaddockIdeas ++ ideas
where
-- Comments need to be sorted by line number for detecting runs of single
-- line comments but @ghcComments@ doesn't always do that even though most
Expand All @@ -142,11 +140,17 @@ commentHint _ m =

Comments pragmas blockHaddocks blocks runHaddocks runs lineHaddocks lines = classifyComments comments

blockHaddockIdeas = concatMap checkEmptyBlockHaddocks blockHaddocks

runReplacements =
(dropBlankLinesHint <$> runHaddocks)
++
(dropBlankLinesHint <$> runs)

ideas = if any fst runReplacements
then concatMap snd runReplacements
else concatMap (check singleLines someLines) comments

-- | Does the commment start with "--"? Can be empty. Excludes haddock single
-- line comments, "-- |" and "-- ^".
isSingle :: LEpaComment -> Bool
Expand Down Expand Up @@ -205,11 +209,14 @@ commentFirstLine comm@(L _ _) = let s = commentText comm
" >>>" -> Just EmptyDoctest
_ -> Nothing

checkEmptyBlockHaddocks :: LEpaComment -> [Idea]
checkEmptyBlockHaddocks comm = [emptyHaddockMulti comm | isHaddockWhitespace comm]

check :: [Int] -> [Int] -> LEpaComment -> [Idea]
check singles somes comm@(L{})
| isHaddockWhitespace comm = traceShow ("haddock", comm) $
if | isMultiline -> [emptyHaddockMulti comm]
| leadingEmptyHaddock ->
-- Multi-line haddock comments are handled elsewhere.
| isHaddockWhitespace comm && not (isCommentMultiline comm) = traceShow ("haddock", comm) $
if | leadingEmptyHaddock ->
traceShow (line, singles, somes) $
[replaceComment "Try this" comm]
--[leadingEmptyIdea EmptyHaddock comm]
Expand Down