-
Notifications
You must be signed in to change notification settings - Fork 982
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
Warn when # noqa: <code>
contains an invalid code
#3339
Comments
The second way is actually kind of a bug but it's consistent with Flake8 IIUC -- |
😮 Damn that could lead me to unexpected ignores, I thought it was normal behavior. I have |
I thought we warned about that, I'll have to double-check. (I see stuff like We don't currently support using the human-readable names for ignores, we need to finalize the names first. |
Wait sorry sorry. |
I misspoke. Let me clarify. |
|
|
If you do |
We should probably warn that |
# noqa: <code>
contains an invalid code
## Summary This PR adds a `ParseError` type to the `noqa` parsing system to enable us to render useful warnings instead of silently failing when parsing `noqa` codes. For example, given `foo.py`: ```python # ruff: noqa: x # ruff: noqa foo # flake8: noqa: F401 import os # noqa: foo-bar ``` We would now output: ```console warning: Invalid `# noqa` directive on line 2: expected a comma-separated list of codes (e.g., `# noqa: F401, F841`). warning: Invalid `# noqa` directive on line 4: expected `:` followed by a comma-separated list of codes (e.g., `# noqa: F401, F841`). warning: Invalid `# noqa` directive on line 6: Flake8's blanket exemption does not support exempting specific codes. To exempt specific codes, use, e.g., `# ruff: noqa: F401, F841` instead. warning: Invalid `# noqa` directive on line 7: expected a comma-separated list of codes (e.g., `# noqa: F401, F841`). ``` There's one important behavior change here too. Right now, with Flake8, if you do `# flake8: noqa: F401`, Flake8 treats that as equivalent to `# flake8: noqa` -- it turns off _all_ diagnostics in the file, not just `F401`. Historically, we respected this... but, I think it's confusing. So we now raise a warning, and don't respect it at all. This will lead to errors in some projects, but I'd argue that right now, those directives are almost certainly behaving in an unintended way for users anyway. Closes #3339.
With the following snippet, I can ignore the issue in 3 ways, but the 4th fails to ignore, and it's not consistant:
# noqa: N815
on the line ✔️# noqa: mixed-case-variable-in-class-scope
on the line ✔️# ruff: noqa: N815
on the first line of the file ✔️# ruff: noqa: mixed-case-variable-in-class-scope
on the first line of the file 🛑The text was updated successfully, but these errors were encountered: