Skip to content

Commit

Permalink
[SIM111] adding regression test for yoda condition of litteral vs obj…
Browse files Browse the repository at this point in the history
…ect's constant

follow-up of fix added in astral-sh#9164
Signed-off-by: Mikael Arguedas <[email protected]>
  • Loading branch information
mikaelarguedas committed Dec 28, 2023
1 parent 8708619 commit f154144
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
SECONDS_IN_DAY == 60 * 60 * 24 # Error in 0.1.8
SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # Error in 0.1.8
{"non-empty-dict": "is-ok"} == DummyHandler.CONFIG
11 == SomeClass().settings.SOME_CONSTANT_VALUE
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,20 @@ SIM300.py:24:1: SIM300 [*] Yoda conditions are discouraged, use `{} == DummyHand
26 26 | # OK
27 27 | compare == "yoda"

SIM300.py:43:1: SIM300 [*] Yoda conditions are discouraged, use `SomeClass().settings.SOME_CONSTANT_VALUE == 11` instead
|
41 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # Error in 0.1.8
42 | {"non-empty-dict": "is-ok"} == DummyHandler.CONFIG
43 | 11 == SomeClass().settings.SOME_CONSTANT_VALUE
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM300
|
= help: Replace Yoda condition with `SomeClass().settings.SOME_CONSTANT_VALUE == 11`

Safe fix
40 40 | SECONDS_IN_DAY == 60 * 60 * 24 # Error in 0.1.8
41 41 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # Error in 0.1.8
42 42 | {"non-empty-dict": "is-ok"} == DummyHandler.CONFIG
43 |-11 == SomeClass().settings.SOME_CONSTANT_VALUE
43 |+SomeClass().settings.SOME_CONSTANT_VALUE == 11


Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,20 @@ SIM300.py:20:1: SIM300 [*] Yoda conditions are discouraged, use `DummyHandler.CO
22 22 | # Errors in stable
23 23 | UPPER_LIST == ['upper']

SIM300.py:43:1: SIM300 [*] Yoda conditions are discouraged, use `SomeClass().settings.SOME_CONSTANT_VALUE == 11` instead
|
41 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # Error in 0.1.8
42 | {"non-empty-dict": "is-ok"} == DummyHandler.CONFIG
43 | 11 == SomeClass().settings.SOME_CONSTANT_VALUE
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM300
|
= help: Replace Yoda condition with `SomeClass().settings.SOME_CONSTANT_VALUE == 11`

Safe fix
40 40 | SECONDS_IN_DAY == 60 * 60 * 24 # Error in 0.1.8
41 41 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # Error in 0.1.8
42 42 | {"non-empty-dict": "is-ok"} == DummyHandler.CONFIG
43 |-11 == SomeClass().settings.SOME_CONSTANT_VALUE
43 |+SomeClass().settings.SOME_CONSTANT_VALUE == 11


0 comments on commit f154144

Please sign in to comment.