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 error despite listed in per-file-ignores #10906

Closed
pjonsson opened this issue Apr 12, 2024 · 7 comments · Fixed by #10908 or #11058
Closed

RUF100 error despite listed in per-file-ignores #10906

pjonsson opened this issue Apr 12, 2024 · 7 comments · Fixed by #10908 or #11058
Assignees
Labels
bug Something isn't working

Comments

@pjonsson
Copy link
Contributor

pjonsson commented Apr 12, 2024

Using Ruff 0.3.7, I tried to select the "RUF" category, and got a RUF100 error. Adding the file to per-file-ignores in pyproject.toml seems to have no effect. The section works for other files/rules in the project, I'm even using it for RUF005.

I have not had the RUF category enabled with previous versions, so I do not know if it this is a regression in Ruff. I searched a bit in the issues, not sure if #6385 or #9300 are related to my problem.

Minimizing the file to this:

class Ruf100:
    def to_dict(self):
        return {
            "really_really_long_key": self.really_really_long_designator(),  # noqa
        }

and putting it in ruf100.py preserves the error:

ruf100.py:4:78: RUF100 [*] Unused blanket `noqa` directive

I would be happy to remove the noqa directive, but Flake8 fails on the real code if I remove it.

Here are what I believe the relevant parts of pyproject.toml are, please let me know if you need more:

[tool.ruff]
src = ["src", "tests"]
target-version = "py310"

[tool.ruff.lint]
select = ["RUF"]
ignore = ["E501"]

[tool.ruff.lint.per-file-ignores]
"src/project/cli.py" = ["UP007", "B008"]

# TO BE FIXED
"src/project/subdir/file.py" = ["RUF015"]
"src/project/otherdir/file2.py" = ["RUF100"]
"ruf100.py" = ["RUF100"]
@charliermarsh charliermarsh self-assigned this Apr 12, 2024
@charliermarsh
Copy link
Member

I think this is just a bug in Ruff.

@charliermarsh charliermarsh added the bug Something isn't working label Apr 12, 2024
@charliermarsh
Copy link
Member

By the way, can you add the code to the # noqa? Ruff would then work as expected, I think.

charliermarsh added a commit that referenced this issue Apr 12, 2024
## Summary

If `RUF100` was included in a per-file-ignore, we respected it on cases
like `# noqa: F401`, but not the blanket variant (`# noqa`).

Closes #10906.
@pjonsson
Copy link
Contributor Author

By the way, can you add the code to the # noqa? Ruff would then work as expected, I think.

Changing the noqa to # noqa: E501 makes Flake8 happy. Ruff is still unhappy, but about something else:

RUF100 [*] Unused `noqa` directive (non-enabled: `E501`)

which is correct since I've put E501 in Ruff's ignore category.

I guess that's a policy decision, should Ruff complain about noqa statements that are only used by other linters. Personally, I'm phasing out flake8 and I'm perfectly fine not using the RUF category until the next Ruff release (and then use a blanket noqa which is what is being used currently).

Glyphack pushed a commit to Glyphack/ruff that referenced this issue Apr 12, 2024
…h#10908)

## Summary

If `RUF100` was included in a per-file-ignore, we respected it on cases
like `# noqa: F401`, but not the blanket variant (`# noqa`).

Closes astral-sh#10906.
@pjonsson
Copy link
Contributor Author

@charliermarsh I just updated to 0.4.1 and still have the same issue, even with ruf100.py that I pasted in this ticket.

$ poetry run ruff check
ruf100.py:4:78: RUF100 [*] Unused blanket `noqa` directive
$ poetry run ruff --version
ruff 0.4.1

I haven't managed to get rid of flake8 yet, so the directive is still in use by flake8.

@charliermarsh
Copy link
Member

Are you sure that your per-file-ignore patterns are defined correctly? Can you confirm that you’re able to ignore other errors in that file?

@charliermarsh
Copy link
Member

Nevermind, I think I understand the case you're hitting. I assume you have no other diagnostics in that file.

@charliermarsh charliermarsh reopened this Apr 20, 2024
charliermarsh added a commit that referenced this issue Apr 20, 2024
## Summary

The existing test didn't cover the case in which there are _no_ other
diagnostics in the file.

Closes #10906.
@Avasam
Copy link

Avasam commented Apr 26, 2024

Changing the noqa to # noqa: E501 makes Flake8 happy. Ruff is still unhappy, but about something else:

RUF100 [*] Unused `noqa` directive (non-enabled: `E501`)

which is correct since I've put E501 in Ruff's ignore category.

You can set E501 as "external" since for you it's a Flake8 rule, not a Ruff one.
https://docs.astral.sh/ruff/settings/#lint_external

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants