Skip to content

Commit

Permalink
make error messages more concise
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jun 27, 2024
1 parent 5410662 commit 7fd2ab6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,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}`"))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
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
| ^^^^^^^^^^^^^^^^^ SIM300
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -270,15 +270,15 @@ 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
15 | B<A[0][0]or B
| ^^^^^^^^^ 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -311,14 +311,14 @@ 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:19:1: SIM300 [*] Yoda conditions are discouraged, use `UPPER_LIST == ['upper']` instead
SIM300.py:19:1: SIM300 [*] Yoda condition detected
|
18 | # Errors in preview
19 | ['upper'] == UPPER_LIST
| ^^^^^^^^^^^^^^^^^^^^^^^ SIM300
20 | {} == DummyHandler.CONFIG
|
= help: Replace Yoda condition with `UPPER_LIST == ['upper']`
= help: Rewrite as `UPPER_LIST == ['upper']`

Safe fix
16 16 | B or(B)<A[0][0]
Expand All @@ -330,7 +330,7 @@ SIM300.py:19:1: SIM300 [*] Yoda conditions are discouraged, use `UPPER_LIST == [
21 21 |
22 22 | # Errors in stable

SIM300.py:20:1: SIM300 [*] Yoda conditions are discouraged, use `DummyHandler.CONFIG == {}` instead
SIM300.py:20:1: SIM300 [*] Yoda condition detected
|
18 | # Errors in preview
19 | ['upper'] == UPPER_LIST
Expand All @@ -339,7 +339,7 @@ SIM300.py:20:1: SIM300 [*] Yoda conditions are discouraged, use `DummyHandler.CO
21 |
22 | # Errors in stable
|
= help: Replace Yoda condition with `DummyHandler.CONFIG == {}`
= help: Rewrite as `DummyHandler.CONFIG == {}`

Safe fix
17 17 |
Expand Down

0 comments on commit 7fd2ab6

Please sign in to comment.