Skip to content

Conversation

@dyegoaurelio
Copy link
Contributor

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.

fixes #362

@github-actions
Copy link

github-actions bot commented Dec 30, 2025

Nixpkgs diff

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.
@dyegoaurelio dyegoaurelio force-pushed the fix-empty-list-idempotency branch from 8c366e4 to 5b32b0a Compare December 30, 2025 23:24
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed in the meeting, looking good!

@MattSturgeon MattSturgeon merged commit ea40c70 into NixOS:master Jan 6, 2026
2 checks passed
@nixos-discourse
Copy link

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

@dyegoaurelio dyegoaurelio deleted the fix-empty-list-idempotency branch January 6, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Reaching a stable list formatting requires formatting twice (2)

4 participants