treefmt icon indicating copy to clipboard operation
treefmt copied to clipboard

Add support for linters

Open zimbatm opened this issue 5 years ago • 15 comments

Unlike formatters, multiple linters can be executed for a single file. Linters sometimes also write back fixes to the file.

The config format has rooms for a [linters.<name>] section.

This needs to be specced-out a bit more.

zimbatm avatar Jan 18 '21 15:01 zimbatm

See also https://github.com/reviewdog/reviewdog

zimbatm avatar Dec 13 '21 18:12 zimbatm

I would like this to work around https://github.com/astral-sh/ruff/issues/8232 by running ruff check --fix && ruff format.

9999years avatar Feb 16 '24 18:02 9999years

Something like this should work:

[formatter.ruff]
command = "sh"
options = ["-c", "ruff check \"$@\" && ruff format \"$@\"", "--"]
includes = ["*.py", "*.pyi"]

zimbatm avatar Feb 19 '24 14:02 zimbatm

First: thanks for this time-saving project!

What's the maintainers' opinion about linters in treefmt-nix?

The docs seem to speak about formatters only, not linters. Also, the name "treefmt" suggests that this is a project about code formatting.

Currently, treefmt-nix offers some linters such as ShellCheck, jsonnet-lint, etc.

Just asking to see what the chances would be for PRs to support more linters like hadolint or Pylint.

Surely, the distinction between formatter and linter isn't always that clear. Some linters have an additional fix mode that may change things, akin to formatting. Technically, most linters in check mode return a non-zero exit status if they discover lints, whereas most formatters exit with status zero even if they changed something (Rufo being an exception unless invoked with --simple-exit).

evolutics avatar Apr 13 '24 14:04 evolutics