Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: commented out lines at the end of a let block should stay in the let block #259

Open
jfly opened this issue Oct 20, 2024 · 0 comments · May be fixed by #270
Open

Suggestion: commented out lines at the end of a let block should stay in the let block #259

jfly opened this issue Oct 20, 2024 · 0 comments · May be fixed by #270
Labels
enhancement New feature or request

Comments

@jfly
Copy link

jfly commented Oct 20, 2024

Description

I often comment/uncomment swaths of code when developing. Since adopting nixfmt, I've found that sometimes those lines of code move around when I comment them, which makes uncommenting them a chore: I have to uncomment them, and then laboriously move them back to where they came from. I'd prefer if nixfmt just didn't move them around.

I haven't been able to find a past discussion about this. I have not read the entire RFC, but https://github.com/nix-rfc-101/rfcs/blob/master/rfcs/0166-nix-formatting.md#comments does say:

  • Anything after the first # of single-line comments must be preserved.
    • This allows the common pattern of prefixing many lines with # to comment them out, without the formatter trying to change anything.

Which (to my eyes) looks like it's talking about this use case (commenting/uncommenting code).

Small example input

(Yes this code is silly. It does reflect a simplified version of things that happen to me when I'm trashing about during development, though.)

let
  # unused = 42;
in
42

Expected output

let
  unused = 42;
in
unused

Actual output

let
in
# unused = 42;
42

Note how unused = 42; got moved out of the let ... in block. This is easier to see in gif form:

2024-10-20_09-31-31_pattern

@piegamesde piegamesde added the enhancement New feature or request label Nov 26, 2024
piegamesde added a commit to piegamesde/nixfmt that referenced this issue Dec 2, 2024
While this was initially introduced for good reasons, as can also be
seen in the diff, that code was written with documentation comments in
mind and not code comments. As per the bug report, the downsides were
deemed to high to keep it in

Fixes NixOS#259
piegamesde added a commit to piegamesde/nixfmt that referenced this issue Dec 3, 2024
While this was initially introduced for good reasons, as can also be
seen in the diff, that code was written with documentation comments in
mind and not code comments. As per the bug report, the downsides were
deemed to high to keep it in

Fixes NixOS#259
@piegamesde piegamesde linked a pull request Dec 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants