Skip to content

Commit

Permalink
Fix star comment non-idempoteny
Browse files Browse the repository at this point in the history
Previously, empty trailing lines in star comments would only get
stripped after the second formatting
  • Loading branch information
infinisil committed Jul 11, 2024
1 parent 6cb8544 commit 99829a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Nixfmt/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ blockComment = try $ preLexeme $ do
isDoc <- try ((True <$ char '*') <* notFollowedBy (char '/')) <|> pure False

chars <- manyTill anySingle $ chunk "*/"
return $ PTBlockComment isDoc $ dropWhile Text.null $ fixIndent pos' $ removeStars pos' $ splitLines $ pack chars
return
. PTBlockComment isDoc
. dropWhile Text.null
. fixIndent pos'
. dropWhileEnd Text.null
. map Text.stripEnd
. removeStars pos'
. splitLines
. pack
$ chars
where
-- Normalize line ends and stuff
splitLines :: Text -> [Text]
Expand Down
5 changes: 5 additions & 0 deletions test/diff/comment/in.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
* test
*/

/* test
* test
*
*/

/*
* FOO
*/
Expand Down
5 changes: 5 additions & 0 deletions test/diff/comment/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
test
*/

/*
test
test
*/

# FOO

/**
Expand Down

0 comments on commit 99829a0

Please sign in to comment.