Skip to content

[flake8-noqa] Implement NQA002, NQA003, NQA004, and NQA005 - #10325

Closed
augustelalande wants to merge 25 commits into
astral-sh:mainfrom
augustelalande:noqa
Closed

[flake8-noqa] Implement NQA002, NQA003, NQA004, and NQA005#10325
augustelalande wants to merge 25 commits into
astral-sh:mainfrom
augustelalande:noqa

Conversation

@augustelalande

Copy link
Copy Markdown
Contributor

Summary

Implement flake8-noqa rules. Part of #850.

Test Plan

Test fixtures have been added for all rules.

@augustelalande
augustelalande marked this pull request as draft March 11, 2024 06:08
@augustelalande

Copy link
Copy Markdown
Contributor Author

I'm hoping someone can help me here. I've basically finalized the rules, but I can't run cargo test because the project won't compile as whole, as can be seen in the failing test runs. It seems to be related to the new plugin being added to the registry, but I can't put my finger on the issue.

Appreciate any help.

@augustelalande augustelalande changed the title [flake8-noqa] Implement NQA002, NQA003, NQA004, and NQA005 [flake8-noqa][help] Implement NQA002, NQA003, NQA004, and NQA005 Mar 11, 2024
@zanieb

zanieb commented Mar 12, 2024

Copy link
Copy Markdown
Member

Hi @augustelalande thanks for the pull request! I haven't looked at the changes yet but I think what you're looking for is cargo dev generate-all to get the schema up to date with your changes.

@augustelalande

This comment was marked as resolved.

@zanieb

zanieb commented Mar 12, 2024

Copy link
Copy Markdown
Member

Ah sorry I looked at the Linux CI which was failing for the reason I said but the Windows CI is indeed failing with that error

error[E0275]: overflow evaluating the requirement `fn() -> RuleCodePrefix: Unpin`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`ruff_linter`)

I'd recommend trying the change they suggest here.

cc @konstin who knows a bit more about Windows-specific Rust problems lots more than me :)

@augustelalande

Copy link
Copy Markdown
Contributor Author

@zanieb It doesn't seem like a windows only issue. Check out the mkdocs check (running ubuntu).

@zanieb

zanieb commented Mar 12, 2024

Copy link
Copy Markdown
Member

Thanks I could reproduce locally.

1ad9498 should resolve this, I pushed to your branch to unblock you and we'll consider it separately in #10373

@augustelalande

Copy link
Copy Markdown
Contributor Author

@zanieb Thanks I was wary of making the change because I was also not sure of the implications.

@augustelalande augustelalande changed the title [flake8-noqa][help] Implement NQA002, NQA003, NQA004, and NQA005 [flake8-noqa] Implement NQA002, NQA003, NQA004, and NQA005 Mar 12, 2024
@github-actions

github-actions Bot commented Mar 12, 2024

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+6 -0 violations, +0 -0 fixes in 2 projects; 42 projects unchanged)

DisnakeDev/disnake (+1 -0 violations, +0 -0 fixes)

+ disnake/utils.py:1161:48: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)

PlasmaPy/PlasmaPy (+5 -0 violations, +0 -0 fixes)

+ plasmapy/particles/tests/test_ionization_collection.py:461:40: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/particles/tests/test_ionization_collection.py:477:40: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/particles/tests/test_ionization_collection.py:494:40: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/particles/tests/test_particle_class.py:557:51: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/utils/tests/test_code_repr.py:327:41: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF100 6 6 0 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+9 -0 violations, +0 -0 fixes in 4 projects; 40 projects unchanged)

DisnakeDev/disnake (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ disnake/utils.py:1161:48: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)

RasaHQ/rasa (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ rasa/core/agent.py:422:99: RUF030 [*] `noqa` directives should have one space after the colon
+ rasa/utils/tensorflow/model_data.py:106:114: RUF030 [*] `noqa` directives should have one space after the colon

PlasmaPy/PlasmaPy (+5 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ plasmapy/particles/tests/test_ionization_collection.py:461:40: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/particles/tests/test_ionization_collection.py:477:40: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/particles/tests/test_ionization_collection.py:494:40: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/particles/tests/test_particle_class.py:557:51: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)
+ plasmapy/utils/tests/test_code_repr.py:327:41: RUF100 [*] Unused `noqa` directive (duplicated: `S307`)

ibis-project/ibis (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ ibis/backends/tests/test_client.py:1544:43: RUF030 [*] `noqa` directives should have one space after the colon

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
RUF100 6 6 0 0 0
RUF030 3 3 0 0 0

@augustelalande
augustelalande marked this pull request as ready for review March 12, 2024 23:32
@MichaReiser

MichaReiser commented Mar 28, 2024

Copy link
Copy Markdown
Member

Thank you @augustelalande, for working on the noqa rules.

I've reviewed the rules and to my understanding:

  • NQA002, NQA003 overlap with PGH004:
    • x = 2 # noqa X100 gets flagged by PGH004, although the error message could be improved (playground)
    • x = 2 # noqa : X400 gets flagged by PGH004. Again, the error message could be improved (playground)
  • NQA005 overlaps with RUF100, although RUF100. RUF100 doesn't flag x = 2 # noqa: D100, D100, D100 today but the rule is focused on identifying unused noqa directives (the explanation is more narrowly focused but I think it fits well from the rule name)

That's why I think that it would be best to integrate:

  • NQA002 and NQA003 into PGH004 by improving the error message and providing a specific fix when we identify the incorrect formatting fix. The rules fit in my view because blanket-noqa is about catching any noqa suppressions that ruff would interpret as blanket noqas
  • NQA005 into RUF100

I don't think there's an existing rule that covers NQA004, although I think it's worth considering moving the rule to RUF, considering that it's the only remaining noqa rule.

What do you think?

@augustelalande

Copy link
Copy Markdown
Contributor Author

That sounds fine to me.

@augustelalande

augustelalande commented Mar 28, 2024

Copy link
Copy Markdown
Contributor Author

Done. I also added a new RUF rule to detect missing spaces after noqa directives, e.g., x = 2 # noqa:X100. Which is the natural counterpart to NQA004.

If you merge this, you may want to consider closing #850, as I don't think anything else from there needs to be added to ruff.

@augustelalande

Copy link
Copy Markdown
Contributor Author

I'm gonna split this into seperate PRs to make it easier to merge.

charliermarsh pushed a commit that referenced this pull request Apr 10, 2024
)

## Summary

Improve `blanket-noqa` error message in cases where codes are provided
but not detected due to formatting issues. Namely `# noqa X100` (missing
colon) or `noqa : X100` (space before colon). The behavior is similar to
`NQA002` and `NQA003` from `flake8-noqa` mentioned in #850. The idea to
merge the rules into `PGH004` was suggested by @MichaReiser
#10325 (comment).

## Test Plan

Test cases added to fixture.
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 12, 2024
…ral-sh#10851)

## Summary

Improve `blanket-noqa` error message in cases where codes are provided
but not detected due to formatting issues. Namely `# noqa X100` (missing
colon) or `noqa : X100` (space before colon). The behavior is similar to
`NQA002` and `NQA003` from `flake8-noqa` mentioned in astral-sh#850. The idea to
merge the rules into `PGH004` was suggested by @MichaReiser
astral-sh#10325 (comment).

## Test Plan

Test cases added to fixture.
@augustelalande
augustelalande deleted the noqa branch April 27, 2024 04:15
charliermarsh pushed a commit that referenced this pull request Apr 27, 2024
…10850)

## Summary

Implement duplicate code detection as part of `RUF100`, mirroring the
behavior of `flake8-noqa` (`NQA005`) mentioned in #850. The idea to
merge the rule into `RUF100` was suggested by @MichaReiser
#10325 (comment).

## Test Plan

Test cases were added to the fixture.
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request May 1, 2026
…851)

## Summary

Improve `blanket-noqa` error message in cases where codes are provided
but not detected due to formatting issues. Namely `# noqa X100` (missing
colon) or `noqa : X100` (space before colon). The behavior is similar to
`NQA002` and `NQA003` from `flake8-noqa` mentioned in #850. The idea to
merge the rules into `PGH004` was suggested by @MichaReiser
astral-sh/ruff#10325 (comment).

## Test Plan

Test cases added to fixture.
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request May 1, 2026
…#10850)

## Summary

Implement duplicate code detection as part of `RUF100`, mirroring the
behavior of `flake8-noqa` (`NQA005`) mentioned in #850. The idea to
merge the rule into `RUF100` was suggested by @MichaReiser
astral-sh/ruff#10325 (comment).

## Test Plan

Test cases were added to the fixture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants