[pep8_naming] Add fixes N804 and N805 - #10215
Merged
Merged
Conversation
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ANN101 | 20 | 10 | 10 | 0 | 0 |
| N805 | 4 | 2 | 2 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+3 -3 violations, +0 -0 fixes in 2 projects; 41 projects unchanged)
bokeh/bokeh (+2 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ tests/unit/bokeh/test_transform.py:65:20: A002 Argument `object` is shadowing a Python builtin - tests/unit/bokeh/test_transform.py:65:20: A002 Argument `object` is shadowing a Python builtin + tests/unit/bokeh/test_transform.py:72:27: A002 Argument `object` is shadowing a Python builtin - tests/unit/bokeh/test_transform.py:72:27: A002 Argument `object` is shadowing a Python builtin
zulip/zulip (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ zerver/models/realms.py:1:1: D100 Missing docstring in public module - zerver/models/realms.py:1:1: D100 Missing docstring in public module
Changes by rule (2 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| A002 | 4 | 2 | 2 | 0 | 0 |
| D100 | 2 | 1 | 1 | 0 | 0 |
| let binding = scope | ||
| .get_all(&first_parameter.name) | ||
| .map(|id| semantic.binding(id)) | ||
| .find(|b| b.kind.is_argument())?; |
Member
There was a problem hiding this comment.
Can you see if Renamer::rename would be useful here?
Contributor
Author
There was a problem hiding this comment.
Renamer::rename would rename all first_parameter.name bindings. I wanted to only renaming references to the argument binding, like this:
But I didn't know the Renamer existed, and from what I've tested Pyright lsp also renames with the same logic as the Renamer. I've updated the PR to use it.
charliermarsh
approved these changes
Mar 4, 2024
charliermarsh
left a comment
Member
There was a problem hiding this comment.
This is nice work, great job figuring this out.
charliermarsh
enabled auto-merge (squash)
March 4, 2024 02:16
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this pull request
Mar 10, 2024
## Summary This PR fixes for `invalid-first-argument` rules. The fixes rename the first argument of methods and class methods to the valid one. References to this argument are also renamed. Fixes are skipped when another argument is named as the valid first argument. The fix is marked as unsafe due The functions for the `N804` and `N805` rules are now merged, as they only differ by the name of the valid first argument. The rules were moved from the AST iteration to the deferred scopes to be in the function scope while creating the fix. ## Test Plan `cargo test`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes for
invalid-first-argumentrules.The fixes rename the first argument of methods and class methods to the valid one. References to this argument are also renamed.
Fixes are skipped when another argument is named as the valid first argument.
The fix is marked as unsafe due
The functions for the
N804andN805rules are now merged, as they only differ by the name of the valid first argument.The rules were moved from the AST iteration to the deferred scopes to be in the function scope while creating the fix.
Test Plan
cargo test