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
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions empty-comment-block-haddocks.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{- |-}
haddockAboveMultiEmpty = 1

{- | -}
haddockAboveMultiEmptySpace = 1

{- |

-}
haddockAboveMultiEmptyLines = 1

haddockBelowMultiEmpty = 1
{- ^-}

haddockBelowMultiEmptySpace = 1
{- ^-}

haddockBelowMultiEmptyLines = 1
{- ^

-}
12 changes: 12 additions & 0 deletions empty-comment-blocks.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{-##-}

{--}
commentMultiEmpty = 1

{- -}
commentMultiEmptySpace = 1

{-

-}
commentMultiEmptyLines = 1
11 changes: 11 additions & 0 deletions empty-comment-mixed.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- |
--
-- Comment with blank line comment space above and below.
--
commentWithSpace = 1

-- | Introduction line.
--
-- Comment with introduction line above and blank line below.
--
CommentWithSpaceOnlyAfter = 1
11 changes: 11 additions & 0 deletions empty-comment-nonempty.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- |
--
--
-- foo
haddockAboveIntoNonEmpty = 1

haddockBelowIntoNonEmpty = 1
-- ^
--
--
-- foo
10 changes: 10 additions & 0 deletions empty-comment-pragmas.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{-##-}
pragmaEmpty = 1

{-# #-}
pragmaEmptySpace = 1

{-#

#-}
pragmaEmptyLines = 1
15 changes: 15 additions & 0 deletions empty-comment-record.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data HaddockSingle = HaddockSingle
{ haddockFieldEmptyBelow :: Int
-- ^
-- |
, haddockFieldAboveEmpty :: Int
, haddockFieldEmptyAfter :: Int -- ^
}

data HaddockMulti = HaddockMulti
{ haddockFieldEmptyBelow :: Int
{- ^-}
{- |-}
, haddockFieldAboveEmpty :: Int
, haddockFieldEmptyAfter :: Int {- ^-}
}
5 changes: 5 additions & 0 deletions empty-comment-single.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- |
haddockAboveSingle = 1

haddockBelowSingle = 1
-- ^
7 changes: 7 additions & 0 deletions empty-comment-singles.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- |
--
haddockAboveSingles = 1

-- |
-- >>>
haddockAboveDoctest = 1
73 changes: 73 additions & 0 deletions example.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
-- | AA
--
--
-- BB
--
--
-- Comment with blank line comment space above and below.
--
--
-- CC
--
--
--
--
commentWithSpace = 1

-- |
--
-- 11
--
--
-- 22
--
--
-- Comment with blank line comment space above and below.
--
--
-- 33
--
commentWithSpace1 = 1

commentWithSpace2 = 1
-- ^
--
-- ZZ
--
--
-- YY
--
--
-- Comment with blank line comment space above and below.
--
--
-- XX
--

-- | A comment as a string.

{- |-}
{--}

--

{-##-}

-- |
-- >>> :{
-- let
-- x = 1
-- y = 2
-- in x + y + multiline
-- :}
-- 6
multiline = 3

{- | >>> :{
let x = 1
y = 2
in x + y + works
:}
6
-}
works = 3
14 changes: 14 additions & 0 deletions src/GHC/Util/ApiAnnotation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module GHC.Util.ApiAnnotation (
, commentText
, GHC.Util.ApiAnnotation.comments
, isCommentMultiline
, isCommentPragma
, isCommentHaddock
, pragmas
, flags
, languagePragmas
Expand Down Expand Up @@ -61,6 +63,18 @@ isCommentMultiline :: LEpaComment -> Bool
isCommentMultiline (L _ (EpaComment (EpaBlockComment _) _)) = True
isCommentMultiline _ = False

isCommentPragma :: LEpaComment -> Bool
isCommentPragma (L _ (EpaComment (EpaBlockComment comm) _)) =
"{-#" `isPrefixOf` comm && "#-}" `isSuffixOf` comm
isCommentPragma _ = False

isCommentHaddock :: LEpaComment -> Bool
isCommentHaddock (L _ (EpaComment (EpaBlockComment comm) _)) =
("{- |" `isPrefixOf` comm || "{- ^" `isPrefixOf` comm) && "-}" `isSuffixOf` comm
isCommentHaddock (L _ (EpaComment (EpaLineComment comm) _)) =
"-- |" `isPrefixOf` comm || "-- ^" `isPrefixOf` comm
isCommentHaddock _ = False

-- Pragmas have the form @{-# ...#-}@.
pragmas :: EpAnnComments -> [(LEpaComment, String)]
pragmas x =
Expand Down
Loading
Loading