[WIP] Sort assignments in sets and "let" #61
Closed
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.
Sort alphabetically identifier keys in sets and let abstraction. More
complex ways to specify keys, like "inherit" statement or interpolated
sorts after plain identifier keys, but without any meaningful order
between themself.
With this change expression "{ b = 10; a = 15; }" transformed into
"{ a = 15; b = 10; }", as indented. Things are getting trickier with
comments.
Nixfmt preserves comments by attaching them to tokens before comment.
It may result to unexpected behaviour in following quite natural case:
This expression gets transformed into following, since from Nixfmt point
of view both comments are attached to "b = 12;" assignment (semicolon,
to be more precise).
DISCUSSION: What should be done about this unexpected behaviour with
comments?
First option is just make this feature opt-in. Second one, probably
harder, it to use some heuristics on whether comment should be attached
to token before or after comment. This is the most complex case I
managed to invent:
Seems that rule "comment that takes whole line is attached to token
after it, otherwise it is attached to token before it" is good
approximation of human perception.
Dear maintainer, what do you suggest and implementation of what approach
you are willing to accept?