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

Comment directive to disable nixfmt #91

Open
PAI5REECHO opened this issue Mar 7, 2022 · 8 comments
Open

Comment directive to disable nixfmt #91

PAI5REECHO opened this issue Mar 7, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@PAI5REECHO
Copy link

Description

It'd be nice to have a way to disable formatting with a comment directive such as nix-community/nixpkgs-fmt#265. If this were added I'd probably switch from using nixpkgs-fmt.

Small example input

# nixfmt: off
{
  "asd" = 123; "abc" = 321;
}
# nixfmt: on

Expected output

# nixfmt: off
{
  "asd" = 123; "abc" = 321;
}
# nixfmt: on

Actual output

# nixfmt: off
{
  "asd" = 123;
  "abc" = 321;
}
# nixfmt: on
@yorickvP yorickvP added the enhancement New feature or request label Apr 18, 2022
@spikespaz
Copy link

Needed especially for this file:
https://github.com/spikespaz/dotfiles/blob/bb736ba0cb12f96024c638df443c623d2e6a1997/packages/ttf-ms-win11/hashes.nix

This is a very top-priority feature for me. I've been wanting it for quite some time.

@piegamesde
Copy link
Member

piegamesde commented Jun 28, 2023

I think this would be incredibly difficult to implement. You are probably better off simply adding that file to your treefmt ignore list.

Edit: Y'all can dislike this comment all you want, this isn't going to make implementing it any easier, and someone skilled and motivated needs to step up to the task

@spikespaz
Copy link

simply adding that file to your treefmt ignore list.

I don't know what treefmt is nor do I use Neovim.

@yorickvP
Copy link
Contributor

yorickvP commented Aug 4, 2023

It would be hard for us to not format certain sections, it would be easy to skip formatting the entire file.

However, there are already ways to achieve this:
treefmt is a formatter runner, that calls the correct formatter for every file in your project. It supports specifying files to keep unformatted.

@spikespaz
Copy link

What about when I use

formatter = eachSystem (system: inputs.nixfmt.packages.${system}.default);

Is there a way to exclude a file then?

@spikespaz
Copy link

Perhaps a directive to disable a file would work well.

# @nixfmt off

For a whole file, not section.

@mbekkomo
Copy link

Any update to this?

@piegamesde
Copy link
Member

Functionally the implementation issue is the same as in #223. To quote my comment from there:

Nixfmt works by pretty-printing parsed AST nodes. How should it deal with partial nodes, especially at the line boundaries? Also, how does it know the base indentation to use? It could calculate that from the global AST but it may differ from the unformatted parts

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

No branches or pull requests

5 participants