Skip to content

Commit

Permalink
Check for empty pragmas
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Aug 4, 2024
1 parent 0351986 commit d5ffa47
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Hint/Comment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
module Hint.Comment(commentHint) where

import Debug.Trace
import Data.Maybe (fromMaybe)

Check failure on line 22 in src/Hint/Comment.hs

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

The import of ‘Data.Maybe’ is redundant

import Hint.Type
import Data.List.Extra
Expand Down Expand Up @@ -127,7 +128,8 @@ commentHint _ m =
traceShow ("runs", fmap commentText <$> runs) $
traceShow ("lineHaddocks", commentText <$> lineHaddocks) $
traceShow ("lines", commentText <$> lines) $
blockHaddockIdeas
pragmaIdeas
++ blockHaddockIdeas
++ blockIdeas
++ ideas
where
Expand All @@ -142,6 +144,7 @@ commentHint _ m =

Comments pragmas blockHaddocks blocks runHaddocks runs lineHaddocks lines = classifyComments comments

pragmaIdeas = concatMap checkEmptyPragma pragmas
blockHaddockIdeas = concatMap checkEmptyBlockHaddock blockHaddocks
blockIdeas = concatMap checkEmptyBlock blocks

Expand Down Expand Up @@ -218,6 +221,9 @@ checkEmptyBlockHaddock comm = [emptyHaddockMulti comm | isHaddockWhitespace comm
checkEmptyBlock :: LEpaComment -> [Idea]
checkEmptyBlock comm = [emptyCommentMulti comm | isCommentWhitespace comm]

checkEmptyPragma :: LEpaComment -> [Idea]
checkEmptyPragma comm = [emptyPragma comm | isPragmaWhitespace comm]

check :: [Int] -> [Int] -> LEpaComment -> [Idea]
check singles somes comm@(L{})
-- Multi-line haddock comments are handled elsewhere.
Expand Down Expand Up @@ -268,6 +274,10 @@ isCommentWhitespace comm@(L (anchor -> span) _ ) =
isHaddockWhitespace :: LEpaComment -> Bool
isHaddockWhitespace comm = isHaddock comm && isStringWhitespace (drop 2 $ commentText comm)

isPragmaWhitespace :: LEpaComment -> Bool
isPragmaWhitespace comm = maybe False isStringWhitespace
(stripSuffix "#" =<< stripPrefix "#" (commentText comm))

isDoctestWhitespace :: LEpaComment -> Bool
isDoctestWhitespace comm@(L (anchor -> span) _ ) = not (isPointRealSpan span) && isDoctest comm

Expand All @@ -283,6 +293,9 @@ leadingEmptyIdea s = emptyComment ("--" ++) $ "Leading empty single-line " ++ pp
emptyMultiIdea :: String -> LEpaComment -> Idea
emptyMultiIdea s = emptyComment (\s -> "{-" ++ s ++ "-}") $ "Empty multi-line " ++ s

emptyPragma :: LEpaComment -> Idea
emptyPragma = emptyComment (\s -> "{-" ++ s ++ "-}") $ "Empty pragma "

emptyCommentMulti, emptyHaddockMulti :: LEpaComment -> Idea
emptyCommentMulti = emptyMultiIdea "comment"
emptyHaddockMulti = emptyMultiIdea "haddock"
Expand Down

0 comments on commit d5ffa47

Please sign in to comment.