nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Ignore .gitignored files?

Open x10an14 opened this issue 1 year ago • 8 comments

Context

Currently testing out the new pkgs.nixfmt-rfc-style, and it's taking forever + erroring out since it attempts to format my .gitignored .direnv/ folder:

-> $ nix fmt
nixfmt: ./.direnv/flake-inputs/5gc4ncnkzcgma8fl1qabm8v9kj7w68gl-source/doc/doc-support: openTempFileWithDefaultPermissions: permission denied (Read-only file system)

Expected behaviour

  • Don't format .gitignored/otherwise explicitly ignored files/files in ignored subfolders of repository.
  • Maybe (additionally, which would solve my issue w/the error, but not the runtime) ignore read-only files.

Things to consider:

  • only support git ignores?
  • support others?
  • add a default list of elements to ignore (like .direnv/, result/)?

x10an14 avatar Feb 25 '24 13:02 x10an14

"Taking forever" ~> 20 seconds, just to not mislead what I meant by that technical hyperbole (but then again, how many expect a linter/formatter to take more than sub two seconds).

x10an14 avatar Feb 25 '24 13:02 x10an14

While nixfmt as of recently has the capability of recursing into subdirectories, usually this should be the job of the program invoking it. Therefore, you should probably take your feature request to the nix fmt developers in your case. For reference, treefmt has a configuration file where you can specify ignores.

Handling gitignore semantics is a highly non-trivial task, and should not be re-implemented for every language formatter.

piegamesde avatar Feb 25 '24 18:02 piegamesde

@piegamesde I don't agree with this. It's really not that hard to support this, because we can use a library like vcs-ignore, which will be good enough for most cases.

infinisil avatar Feb 25 '24 18:02 infinisil

A especially good argument for needing this is that it doesn't make sense for a formatter to accept directory arguments when it doesn't make any effort to filter those directories, because at that point you need to use another tool for filtering anyways and you'd pass files to the formatter instead.

And at that point, nixfmt is essentially not an end-user CLI anymore, which might be fine, but then we should also deprecate passing directories. This needs to be discussed further.

Low priority, but let's keep this open for now.

infinisil avatar Mar 06 '24 17:03 infinisil

Yeah, adding directories has just been added in the last release, and honestly I'm uncertain about that either. There's already issues with symlink handling IIRC.

piegamesde avatar Mar 06 '24 18:03 piegamesde

Btw, vanilla nixfmt behaves the same

acid-bong avatar Mar 11 '24 17:03 acid-bong

(discussed in the team meeting today)

  • With nix fmt this becomes less important
  • There's also treefmt
  • Generally no need to manually call nixfmt
  • Let treefmt or nix take care of this instead.
  • Decision: nixfmt should not be in charge of recursing into directories. That functionality should be removed before the first official release.
  • Short-term can be kept around

So let's not worry about implementing this and instead focus on nix fmt/treefmt integration. We can keep the open issue for now though

infinisil avatar Mar 19 '24 20:03 infinisil

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2024-03-19/41845/1

nixos-discourse avatar Mar 19 '24 20:03 nixos-discourse

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2024-08-06/50222/1

nixos-discourse avatar Aug 06 '24 19:08 nixos-discourse

PR to weakly deprecate recursive mode: https://github.com/NixOS/nixfmt/pull/240

infinisil avatar Aug 26 '24 21:08 infinisil

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2024-12-10-and-2025-01-07/58466/1

nixos-discourse avatar Jan 07 '25 21:01 nixos-discourse