Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Ignore specific rule on per file basis via in-file comment #2446

Closed
mmarras opened this issue Feb 1, 2023 · 8 comments · Fixed by #2978
Closed

Feature request: Ignore specific rule on per file basis via in-file comment #2446

mmarras opened this issue Feb 1, 2023 · 8 comments · Fixed by #2978
Labels
question Asking for support or clarification

Comments

@mmarras
Copy link

mmarras commented Feb 1, 2023

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).

@Alphasite
Copy link

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.

@charliermarsh
Copy link
Member

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?

@charliermarsh charliermarsh added the question Asking for support or clarification label Feb 2, 2023
@mmarras
Copy link
Author

mmarras commented Feb 2, 2023

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.

@charliermarsh
Copy link
Member

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.

@mmarras
Copy link
Author

mmarras commented Feb 17, 2023 via email

@yasirroni
Copy link

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.

@egeres
Copy link

egeres commented Jul 9, 2023

It seems that the # flake8: noqa syntax disables ruff for a singular file without having to edit the pyproject.toml!

@charliermarsh
Copy link
Member

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants