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

RUF100 without selecting the specific error codes #2194

Closed
spaceone opened this issue Jan 26, 2023 · 4 comments
Closed

RUF100 without selecting the specific error codes #2194

spaceone opened this issue Jan 26, 2023 · 4 comments
Labels
question Asking for support or clarification

Comments

@spaceone
Copy link
Contributor

RUF100 removes noqa comments if the lines doesn't have the underlying issue.

This doesn't work if the certain errors aren't part of the --select. I wouldn't have expect this:

$ cat foo.py
from foo import bar  # noqa: F401

foo = lambda x: None  # noqa: E731

import os  # noqa: E403

reload(os)  # noqa: F821
$ ruff --isolated --select RUF100 foo.py
foo.py:1:22: RUF100 Unused `noqa` directive (non-enabled: `F401`)
foo.py:3:23: RUF100 Unused `noqa` directive (non-enabled: `E731`)
foo.py:5:12: RUF100 Unused `noqa` directive (unknown: `E403`)
foo.py:7:13: RUF100 Unused `noqa` directive (non-enabled: `F821`)
Found 4 errors.
4 potentially fixable with the --fix option.
$ ruff --isolated --select RUF100 --fix foo.py
Found 4 errors (4 fixed, 0 remaining).
$ cat foo.py
from foo import bar

foo = lambda x: None

import os

reload(os)

I can also only select codes which ruff is aware of:

$ ruff --isolated --select RUF100,F401,E731,F821 foo.py
foo.py:5:12: RUF100 Unused `noqa` directive (unknown: `E403`)
Found 1 error.
1 potentially fixable with the --fix option.
$ ruff --isolated --select RUF100,F401,E731,F821,E403 foo.py
error: Invalid value 'E403' for '--select <RULE_CODE>': Unknown rule selector `E403`

For more information try '--help'

E403 is not yet supported therefore this is always removed and one cannot prevent this.

@charliermarsh
Copy link
Member

You can add E403 to "external" to prevent this, I think?

[tool.ruff]
external = ["E403"]

@charliermarsh charliermarsh added the question Asking for support or clarification label Jan 26, 2023
@charliermarsh
Copy link
Member

I'd recommend running ruff --extend-select RUF100. That way, it'll enforce your standard configuration.

@spaceone
Copy link
Contributor Author

I somehow need a way to exclusively select RUF100 so that I can get a list of issues (and fixes) only for that one.

@spaceone
Copy link
Contributor Author

fixing only is possible via:
ruff --select ALL --extend-select RUF100 --fix-only --unfixable ALL --fixable RUF100 $(python_files)

selecting only is possible via:
ruff --select ALL --extend-select RUF100 $(python_files) | grep RUF100

(with optional --select ALL)

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

No branches or pull requests

2 participants