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

Specific ruff file ignores ignore everything #3101

Closed
henryiii opened this issue Feb 21, 2023 · 6 comments
Closed

Specific ruff file ignores ignore everything #3101

henryiii opened this issue Feb 21, 2023 · 6 comments
Labels
question Asking for support or clarification

Comments

@henryiii
Copy link
Contributor

The following file:

def main(x):
    a = 1

Shows two errors.

$ ruff check --isolated --extend-select ARG tmp.py
tmp.py:2:10: ARG001 Unused function argument: `x`
tmp.py:3:5: F841 [*] Local variable `a` is assigned to but never used
Found 2 errors.
[*] 1 potentially fixable with the --fix option.

If I add this to the top of the file:

# ruff: noqa: F821

Then both errors disappear, instead of just one. In general, it seems that this is just a blanket noqa. (Also, this should not be too picky - ruff: noqa F821 is an easy mistake to make! I think I'd require a # to put a comment on the same line, if it was my choice).

See pybind/pybind11#4483 (comment).

@charliermarsh
Copy link
Member

Do you know what version this is on?

@charliermarsh
Copy link
Member

In #2978, we added support for directives like # ruff: noqa: F821 which ignore a specific error.

(Note that Flake8 treats # flake8: noqa: F821 as a blanket ignore -- as in, with Flake8, that directive will ignore all errors like you're seeing above.)

@charliermarsh charliermarsh added the question Asking for support or clarification label Feb 21, 2023
@henryiii
Copy link
Contributor Author

henryiii commented Feb 21, 2023

Locally, my version is a bit older due to being from homebrew - 0.0.245. In pre-commit in the original issue, it should have been the latest version, but I can check - ahh, no, it's 0.0.247. I knew that was recent, but not quite how recent. It would be really helpful if # ruff: ignore<stuff> was an error unless <stuff> was recognized and supported or started with a #.

I'll check and report back later tonight!

@charliermarsh
Copy link
Member

So as of that PR, we do throw warnings -- e.g., if you do # ruff: noqa F401:

warning: Unexpected suffix on `noqa` directive: "# ruff: noqa F401"

@charliermarsh
Copy link
Member

(I think that feature shipped in 0.0.248.)

@henryiii
Copy link
Contributor Author

henryiii commented Feb 22, 2023

It oddly prints the warning three times:

warning: Unexpected suffix on `noqa` directive: "# ruff: noqa SIM201 SIM300 SIM202"
warning: Unexpected suffix on `noqa` directive: "# ruff: noqa SIM201 SIM300 SIM202"
warning: Unexpected suffix on `noqa` directive: "# ruff: noqa SIM201 SIM300 SIM202"

Fixed 19 errors:
- tests/test_enum.py:
    10 × SIM201 (negate-equal-op)
     7 × SIM300 (yoda-conditions)
     2 × SIM202 (negate-not-equal-op)

(And I'd be quite fine to have some sort of way to make all warnings errors).

But it does work correctly, and warns as expected, in 0.0.249 (and therefore I'd assume 0.0.251)! Sorry for the noise, I should have tried an update first.

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