ruff
ruff copied to clipboard
Feature request: Ignore specific rule on per file basis via in-file comment
I know we can ignore specific files per toml (per-file-ignores
) and we can also ignore the whole file by putting # ruff: noqa
at the top of the file. Also I can do --extend-ignore=<rule>
.
But how about if I want to ignore only one specifc rule in this file?
The first solution per toml file is not possible for my workflow, the last one does not help with a --pre-commit huck. Would it be possible to allow for it via the in-line comment alla # ruff: noqa: N803
.
Background, I am programming a physics based model and N803 is giving me hell, as we use capital variables because they do have commonly understood physical meaning (t for time and T for temperature).
I suspect extends-per-file-ignore
would solve many of the common use cases for this as well. That is biting me a little as well for our monorepo.
You can always turn off the N803
violation entry (ignore = ["N803"]
in your pyproject.toml
), but I assume you want to keep it enabled, and just disable it in select files -- is that right?
That is correct. I‘m working on a django app, which, as explained earlier, encapsulates a physics based model. So here N803 and friends should be off as upper-case conveys meaning, but in general we like the idea of keeping things lower-case in all other apps in general.
Also for this specific project, the .toml is managed by the repo owner, many people contributing apps. And we have pre-commit hooks in place which prevent you from pushing changes to config files. Of course I could ask for a change or force-commit, I was just thinking why not make #ruff: noqa more fine-grained, would be the perfect match for my use-case.
Flake8 intentionally doesn't support this IIUC. Clippy (Rust's linter) does support something like it although their system is very powerful and effectively allows you to turn rules on and off in any scope.
Awesome! Thanks for picking this one up in no time. On Feb 17, 2023, at 02:59, Charlie Marsh @.***> wrote: Closed #2446 as completed via e081455.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
For those that come here but did not understand how to use that, see the docs on per-file-ignores here. An example is how FastAPI use that here.
It seems that the # flake8: noqa
syntax disables ruff for a singular file without having to edit the pyproject.toml
!
Yes, you can use # ruff: noqa
or (for example) # ruff: noqa: F401
to turn off violations all violations or a specific rule, respectively, within a given file. (# flake8: noqa
is also supported for compatibility.)