nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Comment directive to disable nixfmt

Open PAI5REECHO opened this issue 2 years ago • 6 comments

Description

It'd be nice to have a way to disable formatting with a comment directive such as https://github.com/nix-community/nixpkgs-fmt/issues/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

PAI5REECHO avatar Mar 07 '22 00:03 PAI5REECHO

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.

spikespaz avatar Jun 28 '23 10:06 spikespaz

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

piegamesde avatar Jun 28 '23 10:06 piegamesde

simply adding that file to your treefmt ignore list.

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

spikespaz avatar Jul 28 '23 03:07 spikespaz

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.

yorickvP avatar Aug 04 '23 10:08 yorickvP

What about when I use

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

Is there a way to exclude a file then?

spikespaz avatar Nov 06 '23 08:11 spikespaz

Perhaps a directive to disable a file would work well.

# @nixfmt off

For a whole file, not section.

spikespaz avatar Nov 06 '23 08:11 spikespaz