astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.2k stars 1.11k forks source link

allow to specify output format for --format=text #2350

Open spaceone opened 1 year ago

spaceone commented 1 year ago

flake8 supports specifying the output format via an command line argument: flake8 --format '%(path)s'

allowed specifiers are:

ruff could support --error-format '{path}:{row}:{col} {code}: {text} when --format=text.

This would allow me to easily open all files with specific violations in my editor (vim -p $(ruff --select E --error-format '{path}') )

ngnpope commented 1 year ago

You're likely to end up with duplicates like that if there are multiple violations in a file. So you'd want another flag to avoid duplicate rows, or have ruff deduplicate automatically, or use ruff --select E --error-format '{path}' | sort --unique.

Also note that tabpagemax is set to 10 by default, so you may want to up that when using -p...

charliermarsh commented 1 year ago

I kind of intentionally didn't do this because it felt like it'd add a good deal of complexity, and that in most cases these problems would be solvable by chaining different tools. E.g., in this case, couldn't you pipe the output, split at :, and take everything before it to see the list of paths?

ngnpope commented 1 year ago

This would also be nice for formatting the output when using --statistics.

ngnpope commented 1 year ago

...and that in most cases these problems would be solvable by chaining different tools.

True, this is possible, and you don't even need to fiddle splitting text strings:

ruff check --format=json . | jq --raw-output .[].filename | sort --unique
spaceone commented 1 year ago

You're likely to end up with duplicates like that if there are multiple violations in a file. So you'd want another flag to avoid duplicate rows, or have ruff deduplicate automatically, or use ruff --select E --error-format '{path}' | sort --unique.

jeah, that's not something I expect ruff to do.

Also note that tabpagemax is set to 10 by default, so you may want to up that when using -p...

yes, I have set tabpagemax=30 in vimrc.

Currently I am using vim -p $(ruff --select SIM115 --fix $files | sed -rne 's/:.*//gp'). So this feature would just allow me to not always write that much/complex.

goodspark commented 1 year ago

FWIW, this will make Ruff even easier to drop in with VSCode's built-in flake8 integration, which fails bc VSCode sends --format "%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s" to Ruff. Alternatively, one could just use the Ruff VSCode extension.

ankush commented 7 months ago

pylint format works with vim's quickfix (better than just opening file as this will also use location and error message)

nvim -q <(ruff check --output-format=pylint)