[`flake8-simplify`] Stabilize detection of Yoda conditions for "constant" collections (`SIM300`) (#12050)

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
Charlie Marsh 2024-06-27 06:32:13 -04:00 committed by Micha Reiser
parent 4029a25ebd
commit 04c8597b8a
4 changed files with 69 additions and 456 deletions

View File

@ -9,7 +9,6 @@ mod tests {
use test_case::test_case;
use crate::registry::Rule;
use crate::settings::types::PreviewMode;
use crate::test::test_path;
use crate::{assert_messages, settings};
@ -55,22 +54,4 @@ mod tests {
assert_messages!(snapshot, diagnostics);
Ok(())
}
#[test_case(Rule::YodaConditions, Path::new("SIM300.py"))]
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!(
"preview__{}_{}",
rule_code.noqa_code(),
path.to_string_lossy()
);
let diagnostics = test_path(
Path::new("flake8_simplify").join(path).as_path(),
&settings::LinterSettings {
preview: PreviewMode::Enabled,
..settings::LinterSettings::for_rule(rule_code)
},
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
}
}

View File

@ -16,7 +16,6 @@ use crate::cst::helpers::or_space;
use crate::cst::matchers::{match_comparison, transform_expression};
use crate::fix::edits::pad;
use crate::fix::snippet::SourceCodeSnippet;
use crate::settings::types::PreviewMode;
/// ## What it does
/// Checks for conditions that position a constant on the left-hand side of the
@ -58,26 +57,15 @@ impl Violation for YodaConditions {
#[derive_message_formats]
fn message(&self) -> String {
let YodaConditions { suggestion } = self;
if let Some(suggestion) = suggestion
.as_ref()
.and_then(SourceCodeSnippet::full_display)
{
format!("Yoda conditions are discouraged, use `{suggestion}` instead")
} else {
format!("Yoda conditions are discouraged")
}
format!("Yoda condition detected")
}
fn fix_title(&self) -> Option<String> {
let YodaConditions { suggestion } = self;
suggestion.as_ref().map(|suggestion| {
if let Some(suggestion) = suggestion.full_display() {
format!("Replace Yoda condition with `{suggestion}`")
} else {
format!("Replace Yoda condition")
}
})
suggestion
.as_ref()
.and_then(|suggestion| suggestion.full_display())
.map(|suggestion| format!("Rewrite as `{suggestion}`"))
}
}
@ -94,9 +82,9 @@ enum ConstantLikelihood {
Definitely = 2,
}
impl ConstantLikelihood {
impl From<&Expr> for ConstantLikelihood {
/// Determine the [`ConstantLikelihood`] of an expression.
fn from_expression(expr: &Expr, preview: PreviewMode) -> Self {
fn from(expr: &Expr) -> Self {
match expr {
_ if expr.is_literal_expr() => ConstantLikelihood::Definitely,
Expr::Attribute(ast::ExprAttribute { attr, .. }) => {
@ -105,15 +93,15 @@ impl ConstantLikelihood {
Expr::Name(ast::ExprName { id, .. }) => ConstantLikelihood::from_identifier(id),
Expr::Tuple(ast::ExprTuple { elts, .. }) => elts
.iter()
.map(|expr| ConstantLikelihood::from_expression(expr, preview))
.map(ConstantLikelihood::from)
.min()
.unwrap_or(ConstantLikelihood::Definitely),
Expr::List(ast::ExprList { elts, .. }) if preview.is_enabled() => elts
Expr::List(ast::ExprList { elts, .. }) => elts
.iter()
.map(|expr| ConstantLikelihood::from_expression(expr, preview))
.map(ConstantLikelihood::from)
.min()
.unwrap_or(ConstantLikelihood::Definitely),
Expr::Dict(ast::ExprDict { items, .. }) if preview.is_enabled() => {
Expr::Dict(ast::ExprDict { items, .. }) => {
if items.is_empty() {
ConstantLikelihood::Definitely
} else {
@ -121,18 +109,20 @@ impl ConstantLikelihood {
}
}
Expr::BinOp(ast::ExprBinOp { left, right, .. }) => cmp::min(
ConstantLikelihood::from_expression(left, preview),
ConstantLikelihood::from_expression(right, preview),
ConstantLikelihood::from(&**left),
ConstantLikelihood::from(&**right),
),
Expr::UnaryOp(ast::ExprUnaryOp {
op: UnaryOp::UAdd | UnaryOp::USub | UnaryOp::Invert,
operand,
range: _,
}) => ConstantLikelihood::from_expression(operand, preview),
}) => ConstantLikelihood::from(&**operand),
_ => ConstantLikelihood::Unlikely,
}
}
}
impl ConstantLikelihood {
/// Determine the [`ConstantLikelihood`] of an identifier.
fn from_identifier(identifier: &str) -> Self {
if str::is_cased_uppercase(identifier) {
@ -230,9 +220,7 @@ pub(crate) fn yoda_conditions(
return;
}
if ConstantLikelihood::from_expression(left, checker.settings.preview)
<= ConstantLikelihood::from_expression(right, checker.settings.preview)
{
if ConstantLikelihood::from(left) <= ConstantLikelihood::from(right) {
return;
}

View File

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
---
SIM300.py:2:1: SIM300 [*] Yoda conditions are discouraged, use `compare == "yoda"` instead
SIM300.py:2:1: SIM300 [*] Yoda condition detected
|
1 | # Errors
2 | "yoda" == compare # SIM300
@ -9,7 +9,7 @@ SIM300.py:2:1: SIM300 [*] Yoda conditions are discouraged, use `compare == "yoda
3 | 42 == age # SIM300
4 | ("a", "b") == compare # SIM300
|
= help: Replace Yoda condition with `compare == "yoda"`
= help: Rewrite as `compare == "yoda"`
Safe fix
1 1 | # Errors
@ -19,7 +19,7 @@ SIM300.py:2:1: SIM300 [*] Yoda conditions are discouraged, use `compare == "yoda
4 4 | ("a", "b") == compare # SIM300
5 5 | "yoda" <= compare # SIM300
SIM300.py:3:1: SIM300 [*] Yoda conditions are discouraged, use `age == 42` instead
SIM300.py:3:1: SIM300 [*] Yoda condition detected
|
1 | # Errors
2 | "yoda" == compare # SIM300
@ -28,7 +28,7 @@ SIM300.py:3:1: SIM300 [*] Yoda conditions are discouraged, use `age == 42` inste
4 | ("a", "b") == compare # SIM300
5 | "yoda" <= compare # SIM300
|
= help: Replace Yoda condition with `age == 42`
= help: Rewrite as `age == 42`
Safe fix
1 1 | # Errors
@ -39,7 +39,7 @@ SIM300.py:3:1: SIM300 [*] Yoda conditions are discouraged, use `age == 42` inste
5 5 | "yoda" <= compare # SIM300
6 6 | "yoda" < compare # SIM300
SIM300.py:4:1: SIM300 [*] Yoda conditions are discouraged, use `compare == ("a", "b")` instead
SIM300.py:4:1: SIM300 [*] Yoda condition detected
|
2 | "yoda" == compare # SIM300
3 | 42 == age # SIM300
@ -48,7 +48,7 @@ SIM300.py:4:1: SIM300 [*] Yoda conditions are discouraged, use `compare == ("a",
5 | "yoda" <= compare # SIM300
6 | "yoda" < compare # SIM300
|
= help: Replace Yoda condition with `compare == ("a", "b")`
= help: Rewrite as `compare == ("a", "b")`
Safe fix
1 1 | # Errors
@ -60,7 +60,7 @@ SIM300.py:4:1: SIM300 [*] Yoda conditions are discouraged, use `compare == ("a",
6 6 | "yoda" < compare # SIM300
7 7 | 42 > age # SIM300
SIM300.py:5:1: SIM300 [*] Yoda conditions are discouraged, use `compare >= "yoda"` instead
SIM300.py:5:1: SIM300 [*] Yoda condition detected
|
3 | 42 == age # SIM300
4 | ("a", "b") == compare # SIM300
@ -69,7 +69,7 @@ SIM300.py:5:1: SIM300 [*] Yoda conditions are discouraged, use `compare >= "yoda
6 | "yoda" < compare # SIM300
7 | 42 > age # SIM300
|
= help: Replace Yoda condition with `compare >= "yoda"`
= help: Rewrite as `compare >= "yoda"`
Safe fix
2 2 | "yoda" == compare # SIM300
@ -81,7 +81,7 @@ SIM300.py:5:1: SIM300 [*] Yoda conditions are discouraged, use `compare >= "yoda
7 7 | 42 > age # SIM300
8 8 | -42 > age # SIM300
SIM300.py:6:1: SIM300 [*] Yoda conditions are discouraged, use `compare > "yoda"` instead
SIM300.py:6:1: SIM300 [*] Yoda condition detected
|
4 | ("a", "b") == compare # SIM300
5 | "yoda" <= compare # SIM300
@ -90,7 +90,7 @@ SIM300.py:6:1: SIM300 [*] Yoda conditions are discouraged, use `compare > "yoda"
7 | 42 > age # SIM300
8 | -42 > age # SIM300
|
= help: Replace Yoda condition with `compare > "yoda"`
= help: Rewrite as `compare > "yoda"`
Safe fix
3 3 | 42 == age # SIM300
@ -102,7 +102,7 @@ SIM300.py:6:1: SIM300 [*] Yoda conditions are discouraged, use `compare > "yoda"
8 8 | -42 > age # SIM300
9 9 | +42 > age # SIM300
SIM300.py:7:1: SIM300 [*] Yoda conditions are discouraged, use `age < 42` instead
SIM300.py:7:1: SIM300 [*] Yoda condition detected
|
5 | "yoda" <= compare # SIM300
6 | "yoda" < compare # SIM300
@ -111,7 +111,7 @@ SIM300.py:7:1: SIM300 [*] Yoda conditions are discouraged, use `age < 42` instea
8 | -42 > age # SIM300
9 | +42 > age # SIM300
|
= help: Replace Yoda condition with `age < 42`
= help: Rewrite as `age < 42`
Safe fix
4 4 | ("a", "b") == compare # SIM300
@ -123,7 +123,7 @@ SIM300.py:7:1: SIM300 [*] Yoda conditions are discouraged, use `age < 42` instea
9 9 | +42 > age # SIM300
10 10 | YODA == age # SIM300
SIM300.py:8:1: SIM300 [*] Yoda conditions are discouraged, use `age < -42` instead
SIM300.py:8:1: SIM300 [*] Yoda condition detected
|
6 | "yoda" < compare # SIM300
7 | 42 > age # SIM300
@ -132,7 +132,7 @@ SIM300.py:8:1: SIM300 [*] Yoda conditions are discouraged, use `age < -42` inste
9 | +42 > age # SIM300
10 | YODA == age # SIM300
|
= help: Replace Yoda condition with `age < -42`
= help: Rewrite as `age < -42`
Safe fix
5 5 | "yoda" <= compare # SIM300
@ -144,7 +144,7 @@ SIM300.py:8:1: SIM300 [*] Yoda conditions are discouraged, use `age < -42` inste
10 10 | YODA == age # SIM300
11 11 | YODA > age # SIM300
SIM300.py:9:1: SIM300 [*] Yoda conditions are discouraged, use `age < +42` instead
SIM300.py:9:1: SIM300 [*] Yoda condition detected
|
7 | 42 > age # SIM300
8 | -42 > age # SIM300
@ -153,7 +153,7 @@ SIM300.py:9:1: SIM300 [*] Yoda conditions are discouraged, use `age < +42` inste
10 | YODA == age # SIM300
11 | YODA > age # SIM300
|
= help: Replace Yoda condition with `age < +42`
= help: Rewrite as `age < +42`
Safe fix
6 6 | "yoda" < compare # SIM300
@ -165,7 +165,7 @@ SIM300.py:9:1: SIM300 [*] Yoda conditions are discouraged, use `age < +42` inste
11 11 | YODA > age # SIM300
12 12 | YODA >= age # SIM300
SIM300.py:10:1: SIM300 [*] Yoda conditions are discouraged, use `age == YODA` instead
SIM300.py:10:1: SIM300 [*] Yoda condition detected
|
8 | -42 > age # SIM300
9 | +42 > age # SIM300
@ -174,7 +174,7 @@ SIM300.py:10:1: SIM300 [*] Yoda conditions are discouraged, use `age == YODA` in
11 | YODA > age # SIM300
12 | YODA >= age # SIM300
|
= help: Replace Yoda condition with `age == YODA`
= help: Rewrite as `age == YODA`
Safe fix
7 7 | 42 > age # SIM300
@ -186,7 +186,7 @@ SIM300.py:10:1: SIM300 [*] Yoda conditions are discouraged, use `age == YODA` in
12 12 | YODA >= age # SIM300
13 13 | JediOrder.YODA == age # SIM300
SIM300.py:11:1: SIM300 [*] Yoda conditions are discouraged, use `age < YODA` instead
SIM300.py:11:1: SIM300 [*] Yoda condition detected
|
9 | +42 > age # SIM300
10 | YODA == age # SIM300
@ -195,7 +195,7 @@ SIM300.py:11:1: SIM300 [*] Yoda conditions are discouraged, use `age < YODA` ins
12 | YODA >= age # SIM300
13 | JediOrder.YODA == age # SIM300
|
= help: Replace Yoda condition with `age < YODA`
= help: Rewrite as `age < YODA`
Safe fix
8 8 | -42 > age # SIM300
@ -207,7 +207,7 @@ SIM300.py:11:1: SIM300 [*] Yoda conditions are discouraged, use `age < YODA` ins
13 13 | JediOrder.YODA == age # SIM300
14 14 | 0 < (number - 100) # SIM300
SIM300.py:12:1: SIM300 [*] Yoda conditions are discouraged, use `age <= YODA` instead
SIM300.py:12:1: SIM300 [*] Yoda condition detected
|
10 | YODA == age # SIM300
11 | YODA > age # SIM300
@ -216,7 +216,7 @@ SIM300.py:12:1: SIM300 [*] Yoda conditions are discouraged, use `age <= YODA` in
13 | JediOrder.YODA == age # SIM300
14 | 0 < (number - 100) # SIM300
|
= help: Replace Yoda condition with `age <= YODA`
= help: Rewrite as `age <= YODA`
Safe fix
9 9 | +42 > age # SIM300
@ -228,7 +228,7 @@ SIM300.py:12:1: SIM300 [*] Yoda conditions are discouraged, use `age <= YODA` in
14 14 | 0 < (number - 100) # SIM300
15 15 | B<A[0][0]or B
SIM300.py:13:1: SIM300 [*] Yoda conditions are discouraged, use `age == JediOrder.YODA` instead
SIM300.py:13:1: SIM300 [*] Yoda condition detected
|
11 | YODA > age # SIM300
12 | YODA >= age # SIM300
@ -237,7 +237,7 @@ SIM300.py:13:1: SIM300 [*] Yoda conditions are discouraged, use `age == JediOrde
14 | 0 < (number - 100) # SIM300
15 | B<A[0][0]or B
|
= help: Replace Yoda condition with `age == JediOrder.YODA`
= help: Rewrite as `age == JediOrder.YODA`
Safe fix
10 10 | YODA == age # SIM300
@ -249,7 +249,7 @@ SIM300.py:13:1: SIM300 [*] Yoda conditions are discouraged, use `age == JediOrde
15 15 | B<A[0][0]or B
16 16 | B or(B)<A[0][0]
SIM300.py:14:1: SIM300 [*] Yoda conditions are discouraged, use `(number - 100) > 0` instead
SIM300.py:14:1: SIM300 [*] Yoda condition detected
|
12 | YODA >= age # SIM300
13 | JediOrder.YODA == age # SIM300
@ -258,7 +258,7 @@ SIM300.py:14:1: SIM300 [*] Yoda conditions are discouraged, use `(number - 100)
15 | B<A[0][0]or B
16 | B or(B)<A[0][0]
|
= help: Replace Yoda condition with `(number - 100) > 0`
= help: Rewrite as `(number - 100) > 0`
Safe fix
11 11 | YODA > age # SIM300
@ -270,7 +270,7 @@ SIM300.py:14:1: SIM300 [*] Yoda conditions are discouraged, use `(number - 100)
16 16 | B or(B)<A[0][0]
17 17 |
SIM300.py:15:1: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > B` instead
SIM300.py:15:1: SIM300 [*] Yoda condition detected
|
13 | JediOrder.YODA == age # SIM300
14 | 0 < (number - 100) # SIM300
@ -278,7 +278,7 @@ SIM300.py:15:1: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > B` in
| ^^^^^^^^^ SIM300
16 | B or(B)<A[0][0]
|
= help: Replace Yoda condition with `A[0][0] > B`
= help: Rewrite as `A[0][0] > B`
Safe fix
12 12 | YODA >= age # SIM300
@ -290,7 +290,7 @@ SIM300.py:15:1: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > B` in
17 17 |
18 18 | # Errors in preview
SIM300.py:16:5: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > (B)` instead
SIM300.py:16:5: SIM300 [*] Yoda condition detected
|
14 | 0 < (number - 100) # SIM300
15 | B<A[0][0]or B
@ -299,7 +299,7 @@ SIM300.py:16:5: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > (B)`
17 |
18 | # Errors in preview
|
= help: Replace Yoda condition with `A[0][0] > (B)`
= help: Rewrite as `A[0][0] > (B)`
Safe fix
13 13 | JediOrder.YODA == age # SIM300
@ -311,44 +311,42 @@ SIM300.py:16:5: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > (B)`
18 18 | # Errors in preview
19 19 | ['upper'] == UPPER_LIST
SIM300.py:23:1: SIM300 [*] Yoda conditions are discouraged, use `['upper'] == UPPER_LIST` instead
SIM300.py:19:1: SIM300 [*] Yoda condition detected
|
22 | # Errors in stable
23 | UPPER_LIST == ['upper']
18 | # Errors in preview
19 | ['upper'] == UPPER_LIST
| ^^^^^^^^^^^^^^^^^^^^^^^ SIM300
24 | DummyHandler.CONFIG == {}
20 | {} == DummyHandler.CONFIG
|
= help: Replace Yoda condition with `['upper'] == UPPER_LIST`
= help: Rewrite as `UPPER_LIST == ['upper']`
Safe fix
16 16 | B or(B)<A[0][0]
17 17 |
18 18 | # Errors in preview
19 |-['upper'] == UPPER_LIST
19 |+UPPER_LIST == ['upper']
20 20 | {} == DummyHandler.CONFIG
21 21 |
22 22 | # Errors in stable
23 |-UPPER_LIST == ['upper']
23 |+['upper'] == UPPER_LIST
24 24 | DummyHandler.CONFIG == {}
25 25 |
26 26 | # OK
SIM300.py:24:1: SIM300 [*] Yoda conditions are discouraged, use `{} == DummyHandler.CONFIG` instead
SIM300.py:20:1: SIM300 [*] Yoda condition detected
|
22 | # Errors in stable
23 | UPPER_LIST == ['upper']
24 | DummyHandler.CONFIG == {}
18 | # Errors in preview
19 | ['upper'] == UPPER_LIST
20 | {} == DummyHandler.CONFIG
| ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM300
25 |
26 | # OK
21 |
22 | # Errors in stable
|
= help: Replace Yoda condition with `{} == DummyHandler.CONFIG`
= help: Rewrite as `DummyHandler.CONFIG == {}`
Safe fix
17 17 |
18 18 | # Errors in preview
19 19 | ['upper'] == UPPER_LIST
20 |-{} == DummyHandler.CONFIG
20 |+DummyHandler.CONFIG == {}
21 21 |
22 22 | # Errors in stable
23 23 | UPPER_LIST == ['upper']
24 |-DummyHandler.CONFIG == {}
24 |+{} == DummyHandler.CONFIG
25 25 |
26 26 | # OK
27 27 | compare == "yoda"

View File

@ -1,354 +0,0 @@
---
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
---
SIM300.py:2:1: SIM300 [*] Yoda conditions are discouraged, use `compare == "yoda"` instead
|
1 | # Errors
2 | "yoda" == compare # SIM300
| ^^^^^^^^^^^^^^^^^ SIM300
3 | 42 == age # SIM300
4 | ("a", "b") == compare # SIM300
|
= help: Replace Yoda condition with `compare == "yoda"`
Safe fix
1 1 | # Errors
2 |-"yoda" == compare # SIM300
2 |+compare == "yoda" # SIM300
3 3 | 42 == age # SIM300
4 4 | ("a", "b") == compare # SIM300
5 5 | "yoda" <= compare # SIM300
SIM300.py:3:1: SIM300 [*] Yoda conditions are discouraged, use `age == 42` instead
|
1 | # Errors
2 | "yoda" == compare # SIM300
3 | 42 == age # SIM300
| ^^^^^^^^^ SIM300
4 | ("a", "b") == compare # SIM300
5 | "yoda" <= compare # SIM300
|
= help: Replace Yoda condition with `age == 42`
Safe fix
1 1 | # Errors
2 2 | "yoda" == compare # SIM300
3 |-42 == age # SIM300
3 |+age == 42 # SIM300
4 4 | ("a", "b") == compare # SIM300
5 5 | "yoda" <= compare # SIM300
6 6 | "yoda" < compare # SIM300
SIM300.py:4:1: SIM300 [*] Yoda conditions are discouraged, use `compare == ("a", "b")` instead
|
2 | "yoda" == compare # SIM300
3 | 42 == age # SIM300
4 | ("a", "b") == compare # SIM300
| ^^^^^^^^^^^^^^^^^^^^^ SIM300
5 | "yoda" <= compare # SIM300
6 | "yoda" < compare # SIM300
|
= help: Replace Yoda condition with `compare == ("a", "b")`
Safe fix
1 1 | # Errors
2 2 | "yoda" == compare # SIM300
3 3 | 42 == age # SIM300
4 |-("a", "b") == compare # SIM300
4 |+compare == ("a", "b") # SIM300
5 5 | "yoda" <= compare # SIM300
6 6 | "yoda" < compare # SIM300
7 7 | 42 > age # SIM300
SIM300.py:5:1: SIM300 [*] Yoda conditions are discouraged, use `compare >= "yoda"` instead
|
3 | 42 == age # SIM300
4 | ("a", "b") == compare # SIM300
5 | "yoda" <= compare # SIM300
| ^^^^^^^^^^^^^^^^^ SIM300
6 | "yoda" < compare # SIM300
7 | 42 > age # SIM300
|
= help: Replace Yoda condition with `compare >= "yoda"`
Safe fix
2 2 | "yoda" == compare # SIM300
3 3 | 42 == age # SIM300
4 4 | ("a", "b") == compare # SIM300
5 |-"yoda" <= compare # SIM300
5 |+compare >= "yoda" # SIM300
6 6 | "yoda" < compare # SIM300
7 7 | 42 > age # SIM300
8 8 | -42 > age # SIM300
SIM300.py:6:1: SIM300 [*] Yoda conditions are discouraged, use `compare > "yoda"` instead
|
4 | ("a", "b") == compare # SIM300
5 | "yoda" <= compare # SIM300
6 | "yoda" < compare # SIM300
| ^^^^^^^^^^^^^^^^ SIM300
7 | 42 > age # SIM300
8 | -42 > age # SIM300
|
= help: Replace Yoda condition with `compare > "yoda"`
Safe fix
3 3 | 42 == age # SIM300
4 4 | ("a", "b") == compare # SIM300
5 5 | "yoda" <= compare # SIM300
6 |-"yoda" < compare # SIM300
6 |+compare > "yoda" # SIM300
7 7 | 42 > age # SIM300
8 8 | -42 > age # SIM300
9 9 | +42 > age # SIM300
SIM300.py:7:1: SIM300 [*] Yoda conditions are discouraged, use `age < 42` instead
|
5 | "yoda" <= compare # SIM300
6 | "yoda" < compare # SIM300
7 | 42 > age # SIM300
| ^^^^^^^^ SIM300
8 | -42 > age # SIM300
9 | +42 > age # SIM300
|
= help: Replace Yoda condition with `age < 42`
Safe fix
4 4 | ("a", "b") == compare # SIM300
5 5 | "yoda" <= compare # SIM300
6 6 | "yoda" < compare # SIM300
7 |-42 > age # SIM300
7 |+age < 42 # SIM300
8 8 | -42 > age # SIM300
9 9 | +42 > age # SIM300
10 10 | YODA == age # SIM300
SIM300.py:8:1: SIM300 [*] Yoda conditions are discouraged, use `age < -42` instead
|
6 | "yoda" < compare # SIM300
7 | 42 > age # SIM300
8 | -42 > age # SIM300
| ^^^^^^^^^ SIM300
9 | +42 > age # SIM300
10 | YODA == age # SIM300
|
= help: Replace Yoda condition with `age < -42`
Safe fix
5 5 | "yoda" <= compare # SIM300
6 6 | "yoda" < compare # SIM300
7 7 | 42 > age # SIM300
8 |--42 > age # SIM300
8 |+age < -42 # SIM300
9 9 | +42 > age # SIM300
10 10 | YODA == age # SIM300
11 11 | YODA > age # SIM300
SIM300.py:9:1: SIM300 [*] Yoda conditions are discouraged, use `age < +42` instead
|
7 | 42 > age # SIM300
8 | -42 > age # SIM300
9 | +42 > age # SIM300
| ^^^^^^^^^ SIM300
10 | YODA == age # SIM300
11 | YODA > age # SIM300
|
= help: Replace Yoda condition with `age < +42`
Safe fix
6 6 | "yoda" < compare # SIM300
7 7 | 42 > age # SIM300
8 8 | -42 > age # SIM300
9 |-+42 > age # SIM300
9 |+age < +42 # SIM300
10 10 | YODA == age # SIM300
11 11 | YODA > age # SIM300
12 12 | YODA >= age # SIM300
SIM300.py:10:1: SIM300 [*] Yoda conditions are discouraged, use `age == YODA` instead
|
8 | -42 > age # SIM300
9 | +42 > age # SIM300
10 | YODA == age # SIM300
| ^^^^^^^^^^^ SIM300
11 | YODA > age # SIM300
12 | YODA >= age # SIM300
|
= help: Replace Yoda condition with `age == YODA`
Safe fix
7 7 | 42 > age # SIM300
8 8 | -42 > age # SIM300
9 9 | +42 > age # SIM300
10 |-YODA == age # SIM300
10 |+age == YODA # SIM300
11 11 | YODA > age # SIM300
12 12 | YODA >= age # SIM300
13 13 | JediOrder.YODA == age # SIM300
SIM300.py:11:1: SIM300 [*] Yoda conditions are discouraged, use `age < YODA` instead
|
9 | +42 > age # SIM300
10 | YODA == age # SIM300
11 | YODA > age # SIM300
| ^^^^^^^^^^ SIM300
12 | YODA >= age # SIM300
13 | JediOrder.YODA == age # SIM300
|
= help: Replace Yoda condition with `age < YODA`
Safe fix
8 8 | -42 > age # SIM300
9 9 | +42 > age # SIM300
10 10 | YODA == age # SIM300
11 |-YODA > age # SIM300
11 |+age < YODA # SIM300
12 12 | YODA >= age # SIM300
13 13 | JediOrder.YODA == age # SIM300
14 14 | 0 < (number - 100) # SIM300
SIM300.py:12:1: SIM300 [*] Yoda conditions are discouraged, use `age <= YODA` instead
|
10 | YODA == age # SIM300
11 | YODA > age # SIM300
12 | YODA >= age # SIM300
| ^^^^^^^^^^^ SIM300
13 | JediOrder.YODA == age # SIM300
14 | 0 < (number - 100) # SIM300
|
= help: Replace Yoda condition with `age <= YODA`
Safe fix
9 9 | +42 > age # SIM300
10 10 | YODA == age # SIM300
11 11 | YODA > age # SIM300
12 |-YODA >= age # SIM300
12 |+age <= YODA # SIM300
13 13 | JediOrder.YODA == age # SIM300
14 14 | 0 < (number - 100) # SIM300
15 15 | B<A[0][0]or B
SIM300.py:13:1: SIM300 [*] Yoda conditions are discouraged, use `age == JediOrder.YODA` instead
|
11 | YODA > age # SIM300
12 | YODA >= age # SIM300
13 | JediOrder.YODA == age # SIM300
| ^^^^^^^^^^^^^^^^^^^^^ SIM300
14 | 0 < (number - 100) # SIM300
15 | B<A[0][0]or B
|
= help: Replace Yoda condition with `age == JediOrder.YODA`
Safe fix
10 10 | YODA == age # SIM300
11 11 | YODA > age # SIM300
12 12 | YODA >= age # SIM300
13 |-JediOrder.YODA == age # SIM300
13 |+age == JediOrder.YODA # SIM300
14 14 | 0 < (number - 100) # SIM300
15 15 | B<A[0][0]or B
16 16 | B or(B)<A[0][0]
SIM300.py:14:1: SIM300 [*] Yoda conditions are discouraged, use `(number - 100) > 0` instead
|
12 | YODA >= age # SIM300
13 | JediOrder.YODA == age # SIM300
14 | 0 < (number - 100) # SIM300
| ^^^^^^^^^^^^^^^^^^ SIM300
15 | B<A[0][0]or B
16 | B or(B)<A[0][0]
|
= help: Replace Yoda condition with `(number - 100) > 0`
Safe fix
11 11 | YODA > age # SIM300
12 12 | YODA >= age # SIM300
13 13 | JediOrder.YODA == age # SIM300
14 |-0 < (number - 100) # SIM300
14 |+(number - 100) > 0 # SIM300
15 15 | B<A[0][0]or B
16 16 | B or(B)<A[0][0]
17 17 |
SIM300.py:15:1: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > B` instead
|
13 | JediOrder.YODA == age # SIM300
14 | 0 < (number - 100) # SIM300
15 | B<A[0][0]or B
| ^^^^^^^^^ SIM300
16 | B or(B)<A[0][0]
|
= help: Replace Yoda condition with `A[0][0] > B`
Safe fix
12 12 | YODA >= age # SIM300
13 13 | JediOrder.YODA == age # SIM300
14 14 | 0 < (number - 100) # SIM300
15 |-B<A[0][0]or B
15 |+A[0][0] > B or B
16 16 | B or(B)<A[0][0]
17 17 |
18 18 | # Errors in preview
SIM300.py:16:5: SIM300 [*] Yoda conditions are discouraged, use `A[0][0] > (B)` instead
|
14 | 0 < (number - 100) # SIM300
15 | B<A[0][0]or B
16 | B or(B)<A[0][0]
| ^^^^^^^^^^^ SIM300
17 |
18 | # Errors in preview
|
= help: Replace Yoda condition with `A[0][0] > (B)`
Safe fix
13 13 | JediOrder.YODA == age # SIM300
14 14 | 0 < (number - 100) # SIM300
15 15 | B<A[0][0]or B
16 |-B or(B)<A[0][0]
16 |+B or A[0][0] > (B)
17 17 |
18 18 | # Errors in preview
19 19 | ['upper'] == UPPER_LIST
SIM300.py:19:1: SIM300 [*] Yoda conditions are discouraged, use `UPPER_LIST == ['upper']` instead
|
18 | # Errors in preview
19 | ['upper'] == UPPER_LIST
| ^^^^^^^^^^^^^^^^^^^^^^^ SIM300
20 | {} == DummyHandler.CONFIG
|
= help: Replace Yoda condition with `UPPER_LIST == ['upper']`
Safe fix
16 16 | B or(B)<A[0][0]
17 17 |
18 18 | # Errors in preview
19 |-['upper'] == UPPER_LIST
19 |+UPPER_LIST == ['upper']
20 20 | {} == DummyHandler.CONFIG
21 21 |
22 22 | # Errors in stable
SIM300.py:20:1: SIM300 [*] Yoda conditions are discouraged, use `DummyHandler.CONFIG == {}` instead
|
18 | # Errors in preview
19 | ['upper'] == UPPER_LIST
20 | {} == DummyHandler.CONFIG
| ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM300
21 |
22 | # Errors in stable
|
= help: Replace Yoda condition with `DummyHandler.CONFIG == {}`
Safe fix
17 17 |
18 18 | # Errors in preview
19 19 | ['upper'] == UPPER_LIST
20 |-{} == DummyHandler.CONFIG
20 |+DummyHandler.CONFIG == {}
21 21 |
22 22 | # Errors in stable
23 23 | UPPER_LIST == ['upper']