Skip to content

Commit

Permalink
Merge pull request #220 from NixOS/fix-star-comment-non-idempotency
Browse files Browse the repository at this point in the history
Fix star comment non-idempoteny
  • Loading branch information
infinisil authored Jul 12, 2024
2 parents 278b7ee + c834f33 commit 83de1ec
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 83de1ec

Please sign in to comment.