Skip to content

Commit

Permalink
fix assignment case
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Oct 17, 2023
1 parent df6adf8 commit 551ad16
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
for index, letter in enumerate(letters):
print(letters[index]) # PLR1736
blah = letters[index] # PLR1736
letters[index] = letters[index] # PLR1736 (on the right hand)
letters[index] = "d" # Ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ruff_python_ast::{self as ast, Expr, StmtFor};
use ruff_python_ast::{self as ast, Expr, Stmt, StmtFor};

use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
Expand Down Expand Up @@ -81,6 +81,15 @@ impl<'a> Visitor<'_> for SubscriptVisitor<'a> {
_ => visitor::walk_expr(self, expr),
}
}

fn visit_stmt(&mut self, stmt: &Stmt) {
match stmt {
Stmt::Assign(ast::StmtAssign { value, .. }) => {
self.visit_expr(value);
}
_ => visitor::walk_stmt(self, stmt),
}
}
}

/// PLR1736
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unnecessary_list_index_lookup.py:4:11: PLR1736 [*] Unnecessary list index lookup
4 | print(letters[index]) # PLR1736
| ^^^^^^^^^^^^^^ PLR1736
5 | blah = letters[index] # PLR1736
6 | letters[index] = letters[index] # PLR1736 (on the right hand)
|
= help: Remove unnecessary list index lookup

Expand All @@ -17,13 +18,17 @@ unnecessary_list_index_lookup.py:4:11: PLR1736 [*] Unnecessary list index lookup
4 |- print(letters[index]) # PLR1736
4 |+ print(letter) # PLR1736
5 5 | blah = letters[index] # PLR1736
6 6 | letters[index] = letters[index] # PLR1736 (on the right hand)
7 7 | letters[index] = "d" # Ok

unnecessary_list_index_lookup.py:5:12: PLR1736 [*] Unnecessary list index lookup
|
3 | for index, letter in enumerate(letters):
4 | print(letters[index]) # PLR1736
5 | blah = letters[index] # PLR1736
| ^^^^^^^^^^^^^^ PLR1736
6 | letters[index] = letters[index] # PLR1736 (on the right hand)
7 | letters[index] = "d" # Ok
|
= help: Remove unnecessary list index lookup

Expand All @@ -33,5 +38,25 @@ unnecessary_list_index_lookup.py:5:12: PLR1736 [*] Unnecessary list index lookup
4 4 | print(letters[index]) # PLR1736
5 |- blah = letters[index] # PLR1736
5 |+ blah = letter # PLR1736
6 6 | letters[index] = letters[index] # PLR1736 (on the right hand)
7 7 | letters[index] = "d" # Ok

unnecessary_list_index_lookup.py:6:22: PLR1736 [*] Unnecessary list index lookup
|
4 | print(letters[index]) # PLR1736
5 | blah = letters[index] # PLR1736
6 | letters[index] = letters[index] # PLR1736 (on the right hand)
| ^^^^^^^^^^^^^^ PLR1736
7 | letters[index] = "d" # Ok
|
= help: Remove unnecessary list index lookup

Fix
3 3 | for index, letter in enumerate(letters):
4 4 | print(letters[index]) # PLR1736
5 5 | blah = letters[index] # PLR1736
6 |- letters[index] = letters[index] # PLR1736 (on the right hand)
6 |+ letters[index] = letter # PLR1736 (on the right hand)
7 7 | letters[index] = "d" # Ok


0 comments on commit 551ad16

Please sign in to comment.