Fix empty lists/sets with comments idempotency#363
Merged
MattSturgeon merged 1 commit intoNixOS:masterfrom Jan 6, 2026
Merged
Conversation
Empty lists and attribute sets containing only comments were not formatting idempotently. The issue occurred because block comments (/* ... */) initially parsed as trailing comments on the opening bracket would convert to line comments (# ...) and move inside the Items during formatting. This AST structure change caused different rendering behavior between successive runs. Fixed by ensuring consistent handling of both states: - Modified `renderList` to use `hardline` separator when items contain only comments or when the opening bracket has trivia or the opening bracket has - Updated `isAbsorbable` to treat lists/sets with trivia or only comments as absorbable in assignments This ensures the same formatting output regardless of whether comments still are trailing comments for the opening brackets or have already been converted to list comment items.
8c366e4 to
5b32b0a
Compare
infinisil
approved these changes
Jan 6, 2026
Member
infinisil
left a comment
There was a problem hiding this comment.
Reviewed in the meeting, looking good!
MattSturgeon
approved these changes
Jan 6, 2026
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/formatting-team-meeting-2025-12-09-and-2026-01-06/74041/1 |
This was referenced Jan 8, 2026
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Empty lists and attribute sets containing only comments were not formatting idempotently. The issue occurred because block comments (/* ... */) initially parsed as trailing comments on the opening bracket would convert to line comments (# ...) and move inside the Items during formatting. This AST structure change caused different rendering behavior between successive runs.
Fixed by ensuring consistent handling of both states:
renderListto usehardlineseparator when items contain only comments or when the opening bracket has trivia or the opening bracket hasisAbsorbableto treat lists/sets with trivia or only comments as absorbable in assignmentsThis ensures the same formatting output regardless of whether comments still are trailing comments for the opening brackets or have already been converted to list comment items.
fixes #362