on master help sign in
Implement dropping of trailing whitespace in comments
commit875c79d88d2cdc47d0e4f2d6f1366df746d49e46 authormrkkrp <mark.karpov@tweag.io> dateFri 5 Jul 2019, 20:55 (7 years ago) parent6583ecb
3 files changed+17−2
data/examples/other/trailing-whitespace-out.hs+7 data/examples/other/trailing-whitespace.hs+7 src/Ormolu/Parser/CommentStream.hs+3−2
data/examples/other/trailing-whitespace-out.hsnew file+7
@@ -0,0 +1,7 @@
1+-- Here is a comment with trailing whitespace.
2+foo = 5
3+
4+{- Block comment with trailing whitespace.
5+ Bo.
6+ -}
7+bar = 6
data/examples/other/trailing-whitespace.hsnew file+7
@@ -0,0 +1,7 @@
1+-- Here is a comment with trailing whitespace.
2+foo = 5
3+
4+{- Block comment with trailing whitespace.
5+ Bo.
6+ -}
7+bar = 6
src/Ormolu/Parser/CommentStream.hs+3−2
@@ -18,7 +18,7 @@ where
1818import Data.Char (isSpace)
1919import Data.Data (Data)
2020import Data.Either (partitionEithers)
21−import Data.List (isPrefixOf, sortOn)
21+import Data.List (isPrefixOf, sortOn, dropWhileEnd)
2222import Data.List.NonEmpty (NonEmpty (..))
2323import Data.Maybe (mapMaybe)
2424import Data.Set (Set)
@@ -98,7 +98,7 @@ normalizePragma x =
9898-- each line.
9999
100100mkComment :: RealLocated String -> RealLocated Comment
101−mkComment (L l s) = L l . Comment $
101+mkComment (L l s) = L l . Comment . fmap dropTrailing $
102102 if "{-" `isPrefixOf` s
103103 then case NE.nonEmpty (lines s) of
104104 Nothing -> s :| []
@@ -111,6 +111,7 @@ mkComment (L l s) = L l . Comment $
111111 in x :| (drop n <$> xs)
112112 else s :| []
113113 where
114+ dropTrailing = dropWhileEnd isSpace
114115 startIndent = srcSpanStartCol l - 1
115116
116117-- | Get a 'String' from 'GHC.AnnotationComment'.