@@ -34,40 +34,43 @@ directives = words $
34
34
35
35
36
36
commentHint :: ModuHint
37
- commentHint _ m = concatMap (chk singleLines singleSomeLines ) comments
37
+ commentHint _ m = concatMap (check singleLines someLines ) comments
38
38
where
39
39
comments = ghcComments m
40
-
41
- singleLines :: [Int ]
42
40
singleLines = sort $ commentLine <$> filter isSingle comments
41
+ someLines = sort $ commentLine <$> filter isSingleSome comments
43
42
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 "-- ^".
47
45
isSingle :: LEpaComment -> Bool
48
46
isSingle comm@ (L (anchor -> span ) _) =
49
47
isOneLineRealSpan span
50
48
&& not (isPointRealSpan span )
51
49
&& not (isCommentMultiline comm || isHaddock comm)
52
50
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 "-- "
53
55
isSingleSome :: LEpaComment -> Bool
54
56
isSingleSome comm@ (L (anchor -> span ) _) =
55
57
isOneLineRealSpan span
56
58
&& not (isPointRealSpan span )
57
59
&& not (isCommentMultiline comm || isHaddock comm || isCommentWhitespace comm)
58
60
61
+ -- | The start line number of a comment.
59
62
commentLine :: LEpaComment -> Int
60
63
commentLine (L (anchor -> span ) _) = srcLocLine $ realSrcSpanStart span
61
64
65
+ -- | Is the next line in a string of empty comments leading up to a non-emtpy
66
+ -- comment?
62
67
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 {})
71
74
| isHaddockWhitespace comm =
72
75
if | isMultiline -> [emptyHaddockMulti comm]
73
76
| nextLineIsComment (commentLine comm) singles somes -> []
@@ -83,7 +86,7 @@ chk singles somes comm@(L{})
83
86
isMultiline = isCommentMultiline comm
84
87
s = commentText comm
85
88
name = takeWhile (\ x -> isAlphaNum x || x == ' _' ) $ trimStart s
86
- chk _ _ _ = []
89
+ check _ _ _ = []
87
90
88
91
isHaddockWhitespace :: LEpaComment -> Bool
89
92
isHaddockWhitespace comm = isHaddock comm && isStringWhitespace (drop 2 $ commentText comm)
@@ -92,7 +95,7 @@ isHaddock :: LEpaComment -> Bool
92
95
isHaddock (take 2 . commentText -> s) = " |" == s || " ^" == s
93
96
94
97
isStringWhitespace :: String -> Bool
95
- isStringWhitespace = not . any (`notElem` " \r\n " )
98
+ isStringWhitespace = not . any (`notElem` " \t\ r\n " )
96
99
97
100
isCommentWhitespace :: LEpaComment -> Bool
98
101
isCommentWhitespace comm@ (L (anchor -> span ) _ ) =
0 commit comments