diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py index 4b05877bea3f01..aa4ea1e4dce9cf 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py @@ -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 @@ -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 \ No newline at end of file +a_number = index = a_number + 1 # OK +index = index * index + 10 # OK \ No newline at end of file diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF028_RUF028.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF028_RUF028.py.snap index df8628c0d906ca..e1536cce41926b 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF028_RUF028.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF028_RUF028.py.snap @@ -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. | @@ -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. @@ -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