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 for empty pragmas
  • Loading branch information
philderbeast committed Aug 4, 2024
commit d5ffa47138c8cbb5e13824fd094424719cfdde2b
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 All @@ -30,21 +31,21 @@
import GHC.Data.Strict qualified

directives :: [String]
directives = words $

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: ‘directives’
"LANGUAGE OPTIONS_GHC INCLUDE WARNING DEPRECATED MINIMAL INLINE NOINLINE INLINABLE " ++
"CONLIKE LINE SPECIALIZE SPECIALISE UNPACK NOUNPACK SOURCE"

data Comments = Comments
{ commPragma :: ![LEpaComment]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commPragma’
, commBlockHaddocks :: ![LEpaComment]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commBlockHaddocks’
, commBlocks :: ![LEpaComment]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commBlocks’
-- TODO: Process the different types of block comments; [" |",""].
-- * Haddock comments
-- * Simple comments
, commRunHaddocks :: ![[LEpaComment]]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commRunHaddocks’
, commRuns :: ![[LEpaComment]]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commRuns’
, commLineHaddocks :: ![LEpaComment]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commLineHaddocks’
, commLines :: ![LEpaComment]

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

Defined but not used: record field of Comments ‘commLines’
}

classifyComments :: [LEpaComment] -> Comments
Expand Down Expand Up @@ -96,7 +97,7 @@

ys = (\l ->
[ traceShow ("x", "y", (x, y)) x
| (x,y) <- zip l (tail l)

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

View workflow job for this annotation

GitHub Actions / test (macOS-latest, 9.8)

In the use of ‘tail’
, x /= y || x /= ""
]) (xs ++ [""])

Expand Down Expand Up @@ -127,7 +128,8 @@
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 @@

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 @@
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 @@
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 @@
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
Loading