Skip to content

Commit 5da8d8e

Browse files
committed
Add haddocks.
1 parent 0398fdf commit 5da8d8e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/Hint/Comment.hs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,43 @@ directives = words $
3434

3535

3636
commentHint :: ModuHint
37-
commentHint _ m = concatMap (chk singleLines singleSomeLines) comments
37+
commentHint _ m = concatMap (check singleLines someLines) comments
3838
where
3939
comments = ghcComments m
40-
41-
singleLines :: [Int]
4240
singleLines = sort $ commentLine <$> filter isSingle comments
41+
someLines = sort $ commentLine <$> filter isSingleSome comments
4342

44-
singleSomeLines :: [Int]
45-
singleSomeLines = sort $ commentLine <$> filter isSingleSome comments
46-
43+
-- | Does the commment start with "--"? Can be empty. Excludes haddock single
44+
-- line comments, "-- |" and "-- ^".
4745
isSingle :: LEpaComment -> Bool
4846
isSingle comm@(L (anchor -> span) _) =
4947
isOneLineRealSpan span
5048
&& not (isPointRealSpan span)
5149
&& not (isCommentMultiline comm || isHaddock comm)
5250

51+
-- | A single line comment about something where something is:
52+
-- * Not a haddock comment "-- |" or "-- ^"
53+
-- * Not a multi-line comment "{- ... -}"
54+
-- * Not a whitespace comment "-- "
5355
isSingleSome :: LEpaComment -> Bool
5456
isSingleSome comm@(L (anchor -> span) _) =
5557
isOneLineRealSpan span
5658
&& not (isPointRealSpan span)
5759
&& not (isCommentMultiline comm || isHaddock comm || isCommentWhitespace comm)
5860

61+
-- | The start line number of a comment.
5962
commentLine :: LEpaComment -> Int
6063
commentLine (L (anchor -> span) _) = srcLocLine $ realSrcSpanStart span
6164

65+
-- | Is the next line in a string of empty comments leading up to a non-emtpy
66+
-- comment?
6267
nextLineIsComment :: Int -> [Int] -> [Int] -> Bool
63-
nextLineIsComment x singles somes =
64-
x + 1 `elem` singles
65-
&& (Just True == do
66-
next <- find (x <) somes
67-
pure $ [x + 1 .. next] `isInfixOf` singles)
68-
69-
chk :: [Int] -> [Int] -> LEpaComment -> [Idea]
70-
chk singles somes comm@(L{})
68+
nextLineIsComment x singles somes = Just True == do
69+
next <- find (x <) somes
70+
pure $ [x + 1 .. next] `isInfixOf` singles
71+
72+
check :: [Int] -> [Int] -> LEpaComment -> [Idea]
73+
check singles somes comm@(L{})
7174
| isHaddockWhitespace comm =
7275
if | isMultiline -> [emptyHaddockMulti comm]
7376
| nextLineIsComment (commentLine comm) singles somes -> []
@@ -83,7 +86,7 @@ chk singles somes comm@(L{})
8386
isMultiline = isCommentMultiline comm
8487
s = commentText comm
8588
name = takeWhile (\x -> isAlphaNum x || x == '_') $ trimStart s
86-
chk _ _ _ = []
89+
check _ _ _ = []
8790

8891
isHaddockWhitespace :: LEpaComment -> Bool
8992
isHaddockWhitespace comm = isHaddock comm && isStringWhitespace (drop 2 $ commentText comm)
@@ -92,7 +95,7 @@ isHaddock :: LEpaComment -> Bool
9295
isHaddock (take 2 . commentText -> s) = " |" == s || " ^" == s
9396

9497
isStringWhitespace :: String -> Bool
95-
isStringWhitespace = not . any (`notElem` " \r\n")
98+
isStringWhitespace = not . any (`notElem` " \t\r\n")
9699

97100
isCommentWhitespace :: LEpaComment -> Bool
98101
isCommentWhitespace comm@(L (anchor -> span) _ ) =

0 commit comments

Comments
 (0)