Skip to content

Commit

Permalink
Add two more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lshi18 committed Feb 11, 2024
1 parent 6fbedf6 commit 8bd617a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
5 changes: 4 additions & 1 deletion crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
a_list[1:] = a_list[1:] * 3 # RUF028
a_list[:] = a_list[:] * 3 # RUF028

index = index * (index + 10) # RUF028

class T:
def t(self):
self.a = self.a + 1 # RUF028
Expand All @@ -38,4 +40,5 @@ def t(self):

a_list[0] = a_list[:] * 3 # OK
index = a_number = a_number + 1 # OK
a_number = index = a_number + 1 # OK
a_number = index = a_number + 1 # OK
index = index * index + 10 # OK
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ RUF028.py:29:1: RUF028 [*] Normal assignment with left operand of binary operato
29 |+a_list[1:] *= 3 # RUF028
30 30 | a_list[:] = a_list[:] * 3 # RUF028
31 31 |
32 32 | class T:
32 32 | index = index * (index + 10) # RUF028

RUF028.py:30:1: RUF028 [*] Normal assignment with left operand of binary operator being the same as the target.
|
Expand All @@ -410,7 +410,7 @@ RUF028.py:30:1: RUF028 [*] Normal assignment with left operand of binary operato
30 | a_list[:] = a_list[:] * 3 # RUF028
| ^^^^^^^^^^^^^^^^^^^^^^^^^ RUF028
31 |
32 | class T:
32 | index = index * (index + 10) # RUF028
|
= help: Use augmented assignment instead.

Expand All @@ -421,48 +421,69 @@ RUF028.py:30:1: RUF028 [*] Normal assignment with left operand of binary operato
30 |-a_list[:] = a_list[:] * 3 # RUF028
30 |+a_list[:] *= 3 # RUF028
31 31 |
32 32 | class T:
33 33 | def t(self):
32 32 | index = index * (index + 10) # RUF028
33 33 |

RUF028.py:34:9: RUF028 [*] Normal assignment with left operand of binary operator being the same as the target.
RUF028.py:32:1: RUF028 [*] Normal assignment with left operand of binary operator being the same as the target.
|
32 | class T:
33 | def t(self):
34 | self.a = self.a + 1 # RUF028
| ^^^^^^^^^^^^^^^^^^^ RUF028
35 |
36 | obj = T()
30 | a_list[:] = a_list[:] * 3 # RUF028
31 |
32 | index = index * (index + 10) # RUF028
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF028
33 |
34 | class T:
|
= help: Use augmented assignment instead.

Unsafe fix
29 29 | a_list[1:] = a_list[1:] * 3 # RUF028
30 30 | a_list[:] = a_list[:] * 3 # RUF028
31 31 |
32 32 | class T:
33 33 | def t(self):
34 |- self.a = self.a + 1 # RUF028
34 |+ self.a += 1 # RUF028
35 35 |
36 36 | obj = T()
37 37 | obj.a = obj.a + 1 # RUF028

RUF028.py:37:1: RUF028 [*] Normal assignment with left operand of binary operator being the same as the target.
|
36 | obj = T()
37 | obj.a = obj.a + 1 # RUF028
32 |-index = index * (index + 10) # RUF028
32 |+index *= index + 10 # RUF028
33 33 |
34 34 | class T:
35 35 | def t(self):

RUF028.py:36:9: RUF028 [*] Normal assignment with left operand of binary operator being the same as the target.
|
34 | class T:
35 | def t(self):
36 | self.a = self.a + 1 # RUF028
| ^^^^^^^^^^^^^^^^^^^ RUF028
37 |
38 | obj = T()
|
= help: Use augmented assignment instead.

Unsafe fix
33 33 |
34 34 | class T:
35 35 | def t(self):
36 |- self.a = self.a + 1 # RUF028
36 |+ self.a += 1 # RUF028
37 37 |
38 38 | obj = T()
39 39 | obj.a = obj.a + 1 # RUF028

RUF028.py:39:1: RUF028 [*] Normal assignment with left operand of binary operator being the same as the target.
|
38 | obj = T()
39 | obj.a = obj.a + 1 # RUF028
| ^^^^^^^^^^^^^^^^^ RUF028
38 |
39 | a_list[0] = a_list[:] * 3 # OK
40 |
41 | a_list[0] = a_list[:] * 3 # OK
|
= help: Use augmented assignment instead.

Unsafe fix
34 34 | self.a = self.a + 1 # RUF028
35 35 |
36 36 | obj = T()
37 |-obj.a = obj.a + 1 # RUF028
37 |+obj.a += 1 # RUF028
38 38 |
39 39 | a_list[0] = a_list[:] * 3 # OK
40 40 | index = a_number = a_number + 1 # OK
36 36 | self.a = self.a + 1 # RUF028
37 37 |
38 38 | obj = T()
39 |-obj.a = obj.a + 1 # RUF028
39 |+obj.a += 1 # RUF028
40 40 |
41 41 | a_list[0] = a_list[:] * 3 # OK
42 42 | index = a_number = a_number + 1 # OK


0 comments on commit 8bd617a

Please sign in to comment.