oppiliappan / statix

lints and suggestions for the nix programming language
https://git.peppe.rs/languages/statix/about
MIT License
552 stars 21 forks source link

Disabling checks locally via comments #61

Open figsoda opened 1 year ago

figsoda commented 1 year ago

for example:

{
  # statix-ignore
  overlays.default = final: prev: import ./overlay.nix final prev;
}
{
  # statix-ignore: eta_reduction bool_simplification
  overlays.default = final: prev: import ./overlay.nix final prev;
}
oppiliappan commented 1 year ago

sounds super useful!

montchr commented 1 year ago

I've just run into an example where "fixing" a bool_comparison lint error would end up breaking a module where the option value could be either boolean or string [context]. Since usually I would like to keep the linter rule enabled, suppressing the rule with a comment would be ideal for this exception.

I have zero experience writing Rust, however being eager to learn the language (and potentially see this feature implemented), I went looking for some prior art in other Rust-based linters that I'm aware of. I found this example, which may be of use to whoever ends up working on the feature:

https://github.com/rome/tools/blob/main/crates/rome_js_syntax/src/suppression.rs

Linter — Rome

Suppression comments have the following format:

// rome-ignore lint: <explanation>
// rome-ignore lint/suspicious/noDebugger: <explanation>

Where

  • rome-ignore is the start of a suppression comment;
  • lint suppresses the linter;
  • /suspicious/noDebugger: optional, group and name of the rule you want to suppress;
  • <explanation> explanation why the rule is disabled

Here’s an example:

// rome-ignore lint: reason
debugger;
// rome-ignore lint/suspicious/noDebugger: reason
debugger;