add auto-fix for E225,226,227,228 (#8136)

## Summary

Introduce auto fix for `E225`,`E226`,`E227`,`E228`. This partially
address https://github.com/astral-sh/ruff/issues/8121.

## Test Plan

Already covered.
This commit is contained in:
Weijie Guo 2023-10-24 03:00:42 +08:00 committed by GitHub
parent 5a95b25aa8
commit 7100e12cc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 769 additions and 190 deletions

View file

@ -635,8 +635,9 @@ fn nursery_group_selector_preview_enabled() {
exit_code: 1
----- stdout -----
-:1:1: CPY001 Missing copyright notice at top of file
-:1:2: E225 Missing whitespace around operator
-:1:2: E225 [*] Missing whitespace around operator
Found 2 errors.
[*] 1 fixable with the `--fix` option.
----- stderr -----
warning: The `NURSERY` selector has been deprecated.
@ -655,8 +656,9 @@ fn preview_enabled_prefix() {
exit_code: 1
----- stdout -----
-:1:1: E741 Ambiguous variable name: `I`
-:1:2: E225 Missing whitespace around operator
-:1:2: E225 [*] Missing whitespace around operator
Found 2 errors.
[*] 1 fixable with the `--fix` option.
----- stderr -----
"###);
@ -675,8 +677,9 @@ fn preview_enabled_all() {
-:1:1: E741 Ambiguous variable name: `I`
-:1:1: D100 Missing docstring in public module
-:1:1: CPY001 Missing copyright notice at top of file
-:1:2: E225 Missing whitespace around operator
-:1:2: E225 [*] Missing whitespace around operator
Found 4 errors.
[*] 1 fixable with the `--fix` option.
----- stderr -----
warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`.
@ -695,8 +698,9 @@ fn preview_enabled_direct() {
success: false
exit_code: 1
----- stdout -----
-:1:2: E225 Missing whitespace around operator
-:1:2: E225 [*] Missing whitespace around operator
Found 1 error.
[*] 1 fixable with the `--fix` option.
----- stderr -----
"###);

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{DiagnosticKind, Violation};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, DiagnosticKind, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_parser::TokenKind;
use ruff_text_size::Ranged;
@ -30,11 +30,15 @@ use crate::rules::pycodestyle::rules::logical_lines::LogicalLine;
#[violation]
pub struct MissingWhitespaceAroundOperator;
impl Violation for MissingWhitespaceAroundOperator {
impl AlwaysFixableViolation for MissingWhitespaceAroundOperator {
#[derive_message_formats]
fn message(&self) -> String {
format!("Missing whitespace around operator")
}
fn fix_title(&self) -> String {
format!("Add missing whitespace")
}
}
/// ## What it does
@ -59,11 +63,15 @@ impl Violation for MissingWhitespaceAroundOperator {
#[violation]
pub struct MissingWhitespaceAroundArithmeticOperator;
impl Violation for MissingWhitespaceAroundArithmeticOperator {
impl AlwaysFixableViolation for MissingWhitespaceAroundArithmeticOperator {
#[derive_message_formats]
fn message(&self) -> String {
format!("Missing whitespace around arithmetic operator")
}
fn fix_title(&self) -> String {
format!("Add missing whitespace")
}
}
/// ## What it does
@ -88,11 +96,15 @@ impl Violation for MissingWhitespaceAroundArithmeticOperator {
#[violation]
pub struct MissingWhitespaceAroundBitwiseOrShiftOperator;
impl Violation for MissingWhitespaceAroundBitwiseOrShiftOperator {
impl AlwaysFixableViolation for MissingWhitespaceAroundBitwiseOrShiftOperator {
#[derive_message_formats]
fn message(&self) -> String {
format!("Missing whitespace around bitwise or shift operator")
}
fn fix_title(&self) -> String {
format!("Add missing whitespace")
}
}
/// ## What it does
@ -117,11 +129,15 @@ impl Violation for MissingWhitespaceAroundBitwiseOrShiftOperator {
#[violation]
pub struct MissingWhitespaceAroundModuloOperator;
impl Violation for MissingWhitespaceAroundModuloOperator {
impl AlwaysFixableViolation for MissingWhitespaceAroundModuloOperator {
#[derive_message_formats]
fn message(&self) -> String {
format!("Missing whitespace around modulo operator")
}
fn fix_title(&self) -> String {
format!("Add missing whitespace")
}
}
/// E225, E226, E227, E228
@ -211,15 +227,35 @@ pub(crate) fn missing_whitespace_around_operator(
match (has_leading_trivia, has_trailing_trivia) {
// Operator with trailing but no leading space, enforce consistent spacing.
(false, true) |
(false, true) => {
let mut diagnostic =
Diagnostic::new(diagnostic_kind_for_operator(kind), token.range());
diagnostic.set_fix(Fix::safe_edit(Edit::insertion(
" ".to_string(),
token.start(),
)));
context.push_diagnostic(diagnostic);
}
// Operator with leading but no trailing space, enforce consistent spacing.
(true, false) => {
context.push(MissingWhitespaceAroundOperator, token.range());
let mut diagnostic =
Diagnostic::new(diagnostic_kind_for_operator(kind), token.range());
diagnostic.set_fix(Fix::safe_edit(Edit::insertion(
" ".to_string(),
token.end(),
)));
context.push_diagnostic(diagnostic);
}
// Operator with no space, require spaces if it is required by the operator.
(false, false) => {
if needs_space == NeedsSpace::Yes {
context.push(diagnostic_kind_for_operator(kind), token.range());
let mut diagnostic =
Diagnostic::new(diagnostic_kind_for_operator(kind), token.range());
diagnostic.set_fix(Fix::safe_edits(
Edit::insertion(" ".to_string(), token.start()),
[Edit::insertion(" ".to_string(), token.end())],
));
context.push_diagnostic(diagnostic);
}
}
(true, true) => {

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E22.py:54:11: E225 Missing whitespace around operator
E22.py:54:11: E225 [*] Missing whitespace around operator
|
53 | #: E225
54 | submitted +=1
@ -9,8 +9,19 @@ E22.py:54:11: E225 Missing whitespace around operator
55 | #: E225
56 | submitted+= 1
|
= help: Add missing whitespace
E22.py:56:10: E225 Missing whitespace around operator
Fix
51 51 |
52 52 |
53 53 | #: E225
54 |-submitted +=1
54 |+submitted += 1
55 55 | #: E225
56 56 | submitted+= 1
57 57 | #: E225
E22.py:56:10: E225 [*] Missing whitespace around operator
|
54 | submitted +=1
55 | #: E225
@ -19,8 +30,19 @@ E22.py:56:10: E225 Missing whitespace around operator
57 | #: E225
58 | c =-1
|
= help: Add missing whitespace
E22.py:58:3: E225 Missing whitespace around operator
Fix
53 53 | #: E225
54 54 | submitted +=1
55 55 | #: E225
56 |-submitted+= 1
56 |+submitted += 1
57 57 | #: E225
58 58 | c =-1
59 59 | #: E225
E22.py:58:3: E225 [*] Missing whitespace around operator
|
56 | submitted+= 1
57 | #: E225
@ -29,88 +51,19 @@ E22.py:58:3: E225 Missing whitespace around operator
59 | #: E225
60 | x = x /2 - 1
|
= help: Add missing whitespace
E22.py:60:7: E225 Missing whitespace around operator
|
58 | c =-1
59 | #: E225
60 | x = x /2 - 1
| ^ E225
61 | #: E225
62 | c = alpha -4
|
Fix
55 55 | #: E225
56 56 | submitted+= 1
57 57 | #: E225
58 |-c =-1
58 |+c = -1
59 59 | #: E225
60 60 | x = x /2 - 1
61 61 | #: E225
E22.py:62:11: E225 Missing whitespace around operator
|
60 | x = x /2 - 1
61 | #: E225
62 | c = alpha -4
| ^ E225
63 | #: E225
64 | c = alpha- 4
|
E22.py:64:10: E225 Missing whitespace around operator
|
62 | c = alpha -4
63 | #: E225
64 | c = alpha- 4
| ^ E225
65 | #: E225
66 | z = x **y
|
E22.py:66:7: E225 Missing whitespace around operator
|
64 | c = alpha- 4
65 | #: E225
66 | z = x **y
| ^^ E225
67 | #: E225
68 | z = (x + 1) **y
|
E22.py:68:13: E225 Missing whitespace around operator
|
66 | z = x **y
67 | #: E225
68 | z = (x + 1) **y
| ^^ E225
69 | #: E225
70 | z = (x + 1)** y
|
E22.py:70:12: E225 Missing whitespace around operator
|
68 | z = (x + 1) **y
69 | #: E225
70 | z = (x + 1)** y
| ^^ E225
71 | #: E225
72 | _1kB = _1MB >>10
|
E22.py:72:13: E225 Missing whitespace around operator
|
70 | z = (x + 1)** y
71 | #: E225
72 | _1kB = _1MB >>10
| ^^ E225
73 | #: E225
74 | _1kB = _1MB>> 10
|
E22.py:74:12: E225 Missing whitespace around operator
|
72 | _1kB = _1MB >>10
73 | #: E225
74 | _1kB = _1MB>> 10
| ^^ E225
75 | #: E225 E225
76 | i=i+ 1
|
E22.py:76:2: E225 Missing whitespace around operator
E22.py:76:2: E225 [*] Missing whitespace around operator
|
74 | _1kB = _1MB>> 10
75 | #: E225 E225
@ -119,18 +72,19 @@ E22.py:76:2: E225 Missing whitespace around operator
77 | #: E225 E225
78 | i=i +1
|
= help: Add missing whitespace
E22.py:76:4: E225 Missing whitespace around operator
|
74 | _1kB = _1MB>> 10
75 | #: E225 E225
76 | i=i+ 1
| ^ E225
77 | #: E225 E225
78 | i=i +1
|
Fix
73 73 | #: E225
74 74 | _1kB = _1MB>> 10
75 75 | #: E225 E225
76 |-i=i+ 1
76 |+i = i+ 1
77 77 | #: E225 E225
78 78 | i=i +1
79 79 | #: E225
E22.py:78:2: E225 Missing whitespace around operator
E22.py:78:2: E225 [*] Missing whitespace around operator
|
76 | i=i+ 1
77 | #: E225 E225
@ -139,18 +93,19 @@ E22.py:78:2: E225 Missing whitespace around operator
79 | #: E225
80 | i = 1and 1
|
= help: Add missing whitespace
E22.py:78:5: E225 Missing whitespace around operator
|
76 | i=i+ 1
77 | #: E225 E225
78 | i=i +1
| ^ E225
79 | #: E225
80 | i = 1and 1
|
Fix
75 75 | #: E225 E225
76 76 | i=i+ 1
77 77 | #: E225 E225
78 |-i=i +1
78 |+i = i +1
79 79 | #: E225
80 80 | i = 1and 1
81 81 | #: E225
E22.py:80:6: E225 Missing whitespace around operator
E22.py:80:6: E225 [*] Missing whitespace around operator
|
78 | i=i +1
79 | #: E225
@ -159,8 +114,19 @@ E22.py:80:6: E225 Missing whitespace around operator
81 | #: E225
82 | i = 1or 0
|
= help: Add missing whitespace
E22.py:82:6: E225 Missing whitespace around operator
Fix
77 77 | #: E225 E225
78 78 | i=i +1
79 79 | #: E225
80 |-i = 1and 1
80 |+i = 1 and 1
81 81 | #: E225
82 82 | i = 1or 0
83 83 | #: E225
E22.py:82:6: E225 [*] Missing whitespace around operator
|
80 | i = 1and 1
81 | #: E225
@ -169,8 +135,19 @@ E22.py:82:6: E225 Missing whitespace around operator
83 | #: E225
84 | 1is 1
|
= help: Add missing whitespace
E22.py:84:2: E225 Missing whitespace around operator
Fix
79 79 | #: E225
80 80 | i = 1and 1
81 81 | #: E225
82 |-i = 1or 0
82 |+i = 1 or 0
83 83 | #: E225
84 84 | 1is 1
85 85 | #: E225
E22.py:84:2: E225 [*] Missing whitespace around operator
|
82 | i = 1or 0
83 | #: E225
@ -179,8 +156,19 @@ E22.py:84:2: E225 Missing whitespace around operator
85 | #: E225
86 | 1in []
|
= help: Add missing whitespace
E22.py:86:2: E225 Missing whitespace around operator
Fix
81 81 | #: E225
82 82 | i = 1or 0
83 83 | #: E225
84 |-1is 1
84 |+1 is 1
85 85 | #: E225
86 86 | 1in []
87 87 | #: E225
E22.py:86:2: E225 [*] Missing whitespace around operator
|
84 | 1is 1
85 | #: E225
@ -189,28 +177,19 @@ E22.py:86:2: E225 Missing whitespace around operator
87 | #: E225
88 | i = 1 @2
|
= help: Add missing whitespace
E22.py:88:7: E225 Missing whitespace around operator
|
86 | 1in []
87 | #: E225
88 | i = 1 @2
| ^ E225
89 | #: E225
90 | i = 1@ 2
|
Fix
83 83 | #: E225
84 84 | 1is 1
85 85 | #: E225
86 |-1in []
86 |+1 in []
87 87 | #: E225
88 88 | i = 1 @2
89 89 | #: E225
E22.py:90:6: E225 Missing whitespace around operator
|
88 | i = 1 @2
89 | #: E225
90 | i = 1@ 2
| ^ E225
91 | #: E225 E226
92 | i=i+1
|
E22.py:92:2: E225 Missing whitespace around operator
E22.py:92:2: E225 [*] Missing whitespace around operator
|
90 | i = 1@ 2
91 | #: E225 E226
@ -219,8 +198,19 @@ E22.py:92:2: E225 Missing whitespace around operator
93 | #: E225 E226
94 | i =i+1
|
= help: Add missing whitespace
E22.py:94:3: E225 Missing whitespace around operator
Fix
89 89 | #: E225
90 90 | i = 1@ 2
91 91 | #: E225 E226
92 |-i=i+1
92 |+i = i+1
93 93 | #: E225 E226
94 94 | i =i+1
95 95 | #: E225 E226
E22.py:94:3: E225 [*] Missing whitespace around operator
|
92 | i=i+1
93 | #: E225 E226
@ -229,8 +219,19 @@ E22.py:94:3: E225 Missing whitespace around operator
95 | #: E225 E226
96 | i= i+1
|
= help: Add missing whitespace
E22.py:96:2: E225 Missing whitespace around operator
Fix
91 91 | #: E225 E226
92 92 | i=i+1
93 93 | #: E225 E226
94 |-i =i+1
94 |+i = i+1
95 95 | #: E225 E226
96 96 | i= i+1
97 97 | #: E225 E226
E22.py:96:2: E225 [*] Missing whitespace around operator
|
94 | i =i+1
95 | #: E225 E226
@ -239,34 +240,16 @@ E22.py:96:2: E225 Missing whitespace around operator
97 | #: E225 E226
98 | c = (a +b)*(a - b)
|
= help: Add missing whitespace
E22.py:98:8: E225 Missing whitespace around operator
|
96 | i= i+1
97 | #: E225 E226
98 | c = (a +b)*(a - b)
| ^ E225
99 | #: E225 E226
100 | c = (a+ b)*(a - b)
|
E22.py:100:7: E225 Missing whitespace around operator
|
98 | c = (a +b)*(a - b)
99 | #: E225 E226
100 | c = (a+ b)*(a - b)
| ^ E225
101 | #:
|
E22.py:154:11: E225 Missing whitespace around operator
|
152 | func2(lambda a, b=h[:], c=0: (a, b, c))
153 | if not -5 < x < +5:
154 | print >>sys.stderr, "x is out of range."
| ^^ E225
155 | print >> sys.stdout, "x is an integer."
156 | x = x / 2 - 1
|
Fix
93 93 | #: E225 E226
94 94 | i =i+1
95 95 | #: E225 E226
96 |-i= i+1
96 |+i = i+1
97 97 | #: E225 E226
98 98 | c = (a +b)*(a - b)
99 99 | #: E225 E226

View file

@ -1,7 +1,217 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E22.py:92:4: E226 Missing whitespace around arithmetic operator
E22.py:60:7: E226 [*] Missing whitespace around arithmetic operator
|
58 | c =-1
59 | #: E225
60 | x = x /2 - 1
| ^ E226
61 | #: E225
62 | c = alpha -4
|
= help: Add missing whitespace
Fix
57 57 | #: E225
58 58 | c =-1
59 59 | #: E225
60 |-x = x /2 - 1
60 |+x = x / 2 - 1
61 61 | #: E225
62 62 | c = alpha -4
63 63 | #: E225
E22.py:62:11: E226 [*] Missing whitespace around arithmetic operator
|
60 | x = x /2 - 1
61 | #: E225
62 | c = alpha -4
| ^ E226
63 | #: E225
64 | c = alpha- 4
|
= help: Add missing whitespace
Fix
59 59 | #: E225
60 60 | x = x /2 - 1
61 61 | #: E225
62 |-c = alpha -4
62 |+c = alpha - 4
63 63 | #: E225
64 64 | c = alpha- 4
65 65 | #: E225
E22.py:64:10: E226 [*] Missing whitespace around arithmetic operator
|
62 | c = alpha -4
63 | #: E225
64 | c = alpha- 4
| ^ E226
65 | #: E225
66 | z = x **y
|
= help: Add missing whitespace
Fix
61 61 | #: E225
62 62 | c = alpha -4
63 63 | #: E225
64 |-c = alpha- 4
64 |+c = alpha - 4
65 65 | #: E225
66 66 | z = x **y
67 67 | #: E225
E22.py:66:7: E226 [*] Missing whitespace around arithmetic operator
|
64 | c = alpha- 4
65 | #: E225
66 | z = x **y
| ^^ E226
67 | #: E225
68 | z = (x + 1) **y
|
= help: Add missing whitespace
Fix
63 63 | #: E225
64 64 | c = alpha- 4
65 65 | #: E225
66 |-z = x **y
66 |+z = x ** y
67 67 | #: E225
68 68 | z = (x + 1) **y
69 69 | #: E225
E22.py:68:13: E226 [*] Missing whitespace around arithmetic operator
|
66 | z = x **y
67 | #: E225
68 | z = (x + 1) **y
| ^^ E226
69 | #: E225
70 | z = (x + 1)** y
|
= help: Add missing whitespace
Fix
65 65 | #: E225
66 66 | z = x **y
67 67 | #: E225
68 |-z = (x + 1) **y
68 |+z = (x + 1) ** y
69 69 | #: E225
70 70 | z = (x + 1)** y
71 71 | #: E225
E22.py:70:12: E226 [*] Missing whitespace around arithmetic operator
|
68 | z = (x + 1) **y
69 | #: E225
70 | z = (x + 1)** y
| ^^ E226
71 | #: E225
72 | _1kB = _1MB >>10
|
= help: Add missing whitespace
Fix
67 67 | #: E225
68 68 | z = (x + 1) **y
69 69 | #: E225
70 |-z = (x + 1)** y
70 |+z = (x + 1) ** y
71 71 | #: E225
72 72 | _1kB = _1MB >>10
73 73 | #: E225
E22.py:76:4: E226 [*] Missing whitespace around arithmetic operator
|
74 | _1kB = _1MB>> 10
75 | #: E225 E225
76 | i=i+ 1
| ^ E226
77 | #: E225 E225
78 | i=i +1
|
= help: Add missing whitespace
Fix
73 73 | #: E225
74 74 | _1kB = _1MB>> 10
75 75 | #: E225 E225
76 |-i=i+ 1
76 |+i=i + 1
77 77 | #: E225 E225
78 78 | i=i +1
79 79 | #: E225
E22.py:78:5: E226 [*] Missing whitespace around arithmetic operator
|
76 | i=i+ 1
77 | #: E225 E225
78 | i=i +1
| ^ E226
79 | #: E225
80 | i = 1and 1
|
= help: Add missing whitespace
Fix
75 75 | #: E225 E225
76 76 | i=i+ 1
77 77 | #: E225 E225
78 |-i=i +1
78 |+i=i + 1
79 79 | #: E225
80 80 | i = 1and 1
81 81 | #: E225
E22.py:88:7: E226 [*] Missing whitespace around arithmetic operator
|
86 | 1in []
87 | #: E225
88 | i = 1 @2
| ^ E226
89 | #: E225
90 | i = 1@ 2
|
= help: Add missing whitespace
Fix
85 85 | #: E225
86 86 | 1in []
87 87 | #: E225
88 |-i = 1 @2
88 |+i = 1 @ 2
89 89 | #: E225
90 90 | i = 1@ 2
91 91 | #: E225 E226
E22.py:90:6: E226 [*] Missing whitespace around arithmetic operator
|
88 | i = 1 @2
89 | #: E225
90 | i = 1@ 2
| ^ E226
91 | #: E225 E226
92 | i=i+1
|
= help: Add missing whitespace
Fix
87 87 | #: E225
88 88 | i = 1 @2
89 89 | #: E225
90 |-i = 1@ 2
90 |+i = 1 @ 2
91 91 | #: E225 E226
92 92 | i=i+1
93 93 | #: E225 E226
E22.py:92:4: E226 [*] Missing whitespace around arithmetic operator
|
90 | i = 1@ 2
91 | #: E225 E226
@ -10,8 +220,19 @@ E22.py:92:4: E226 Missing whitespace around arithmetic operator
93 | #: E225 E226
94 | i =i+1
|
= help: Add missing whitespace
E22.py:94:5: E226 Missing whitespace around arithmetic operator
Fix
89 89 | #: E225
90 90 | i = 1@ 2
91 91 | #: E225 E226
92 |-i=i+1
92 |+i=i + 1
93 93 | #: E225 E226
94 94 | i =i+1
95 95 | #: E225 E226
E22.py:94:5: E226 [*] Missing whitespace around arithmetic operator
|
92 | i=i+1
93 | #: E225 E226
@ -20,8 +241,19 @@ E22.py:94:5: E226 Missing whitespace around arithmetic operator
95 | #: E225 E226
96 | i= i+1
|
= help: Add missing whitespace
E22.py:96:5: E226 Missing whitespace around arithmetic operator
Fix
91 91 | #: E225 E226
92 92 | i=i+1
93 93 | #: E225 E226
94 |-i =i+1
94 |+i =i + 1
95 95 | #: E225 E226
96 96 | i= i+1
97 97 | #: E225 E226
E22.py:96:5: E226 [*] Missing whitespace around arithmetic operator
|
94 | i =i+1
95 | #: E225 E226
@ -30,8 +262,19 @@ E22.py:96:5: E226 Missing whitespace around arithmetic operator
97 | #: E225 E226
98 | c = (a +b)*(a - b)
|
= help: Add missing whitespace
E22.py:98:11: E226 Missing whitespace around arithmetic operator
Fix
93 93 | #: E225 E226
94 94 | i =i+1
95 95 | #: E225 E226
96 |-i= i+1
96 |+i= i + 1
97 97 | #: E225 E226
98 98 | c = (a +b)*(a - b)
99 99 | #: E225 E226
E22.py:98:8: E226 [*] Missing whitespace around arithmetic operator
|
96 | i= i+1
97 | #: E225 E226
@ -40,8 +283,40 @@ E22.py:98:11: E226 Missing whitespace around arithmetic operator
99 | #: E225 E226
100 | c = (a+ b)*(a - b)
|
= help: Add missing whitespace
E22.py:100:11: E226 Missing whitespace around arithmetic operator
Fix
95 95 | #: E225 E226
96 96 | i= i+1
97 97 | #: E225 E226
98 |-c = (a +b)*(a - b)
98 |+c = (a + b)*(a - b)
99 99 | #: E225 E226
100 100 | c = (a+ b)*(a - b)
101 101 | #:
E22.py:98:11: E226 [*] Missing whitespace around arithmetic operator
|
96 | i= i+1
97 | #: E225 E226
98 | c = (a +b)*(a - b)
| ^ E226
99 | #: E225 E226
100 | c = (a+ b)*(a - b)
|
= help: Add missing whitespace
Fix
95 95 | #: E225 E226
96 96 | i= i+1
97 97 | #: E225 E226
98 |-c = (a +b)*(a - b)
98 |+c = (a +b) * (a - b)
99 99 | #: E225 E226
100 100 | c = (a+ b)*(a - b)
101 101 | #:
E22.py:100:7: E226 [*] Missing whitespace around arithmetic operator
|
98 | c = (a +b)*(a - b)
99 | #: E225 E226
@ -49,8 +324,39 @@ E22.py:100:11: E226 Missing whitespace around arithmetic operator
| ^ E226
101 | #:
|
= help: Add missing whitespace
E22.py:104:6: E226 Missing whitespace around arithmetic operator
Fix
97 97 | #: E225 E226
98 98 | c = (a +b)*(a - b)
99 99 | #: E225 E226
100 |-c = (a+ b)*(a - b)
100 |+c = (a + b)*(a - b)
101 101 | #:
102 102 |
103 103 | #: E226
E22.py:100:11: E226 [*] Missing whitespace around arithmetic operator
|
98 | c = (a +b)*(a - b)
99 | #: E225 E226
100 | c = (a+ b)*(a - b)
| ^ E226
101 | #:
|
= help: Add missing whitespace
Fix
97 97 | #: E225 E226
98 98 | c = (a +b)*(a - b)
99 99 | #: E225 E226
100 |-c = (a+ b)*(a - b)
100 |+c = (a+ b) * (a - b)
101 101 | #:
102 102 |
103 103 | #: E226
E22.py:104:6: E226 [*] Missing whitespace around arithmetic operator
|
103 | #: E226
104 | z = 2//30
@ -58,8 +364,19 @@ E22.py:104:6: E226 Missing whitespace around arithmetic operator
105 | #: E226 E226
106 | c = (a+b) * (a-b)
|
= help: Add missing whitespace
E22.py:106:7: E226 Missing whitespace around arithmetic operator
Fix
101 101 | #:
102 102 |
103 103 | #: E226
104 |-z = 2//30
104 |+z = 2 // 30
105 105 | #: E226 E226
106 106 | c = (a+b) * (a-b)
107 107 | #: E226
E22.py:106:7: E226 [*] Missing whitespace around arithmetic operator
|
104 | z = 2//30
105 | #: E226 E226
@ -68,8 +385,19 @@ E22.py:106:7: E226 Missing whitespace around arithmetic operator
107 | #: E226
108 | norman = True+False
|
= help: Add missing whitespace
E22.py:106:15: E226 Missing whitespace around arithmetic operator
Fix
103 103 | #: E226
104 104 | z = 2//30
105 105 | #: E226 E226
106 |-c = (a+b) * (a-b)
106 |+c = (a + b) * (a-b)
107 107 | #: E226
108 108 | norman = True+False
109 109 | #: E226
E22.py:106:15: E226 [*] Missing whitespace around arithmetic operator
|
104 | z = 2//30
105 | #: E226 E226
@ -78,8 +406,19 @@ E22.py:106:15: E226 Missing whitespace around arithmetic operator
107 | #: E226
108 | norman = True+False
|
= help: Add missing whitespace
E22.py:110:6: E226 Missing whitespace around arithmetic operator
Fix
103 103 | #: E226
104 104 | z = 2//30
105 105 | #: E226 E226
106 |-c = (a+b) * (a-b)
106 |+c = (a+b) * (a - b)
107 107 | #: E226
108 108 | norman = True+False
109 109 | #: E226
E22.py:110:6: E226 [*] Missing whitespace around arithmetic operator
|
108 | norman = True+False
109 | #: E226
@ -88,8 +427,19 @@ E22.py:110:6: E226 Missing whitespace around arithmetic operator
111 | #: E226
112 | x = x/2 - 1
|
= help: Add missing whitespace
E22.py:112:6: E226 Missing whitespace around arithmetic operator
Fix
107 107 | #: E226
108 108 | norman = True+False
109 109 | #: E226
110 |-x = x*2 - 1
110 |+x = x * 2 - 1
111 111 | #: E226
112 112 | x = x/2 - 1
113 113 | #: E226 E226
E22.py:112:6: E226 [*] Missing whitespace around arithmetic operator
|
110 | x = x*2 - 1
111 | #: E226
@ -98,8 +448,19 @@ E22.py:112:6: E226 Missing whitespace around arithmetic operator
113 | #: E226 E226
114 | hypot2 = x*x + y*y
|
= help: Add missing whitespace
E22.py:114:11: E226 Missing whitespace around arithmetic operator
Fix
109 109 | #: E226
110 110 | x = x*2 - 1
111 111 | #: E226
112 |-x = x/2 - 1
112 |+x = x / 2 - 1
113 113 | #: E226 E226
114 114 | hypot2 = x*x + y*y
115 115 | #: E226
E22.py:114:11: E226 [*] Missing whitespace around arithmetic operator
|
112 | x = x/2 - 1
113 | #: E226 E226
@ -108,8 +469,19 @@ E22.py:114:11: E226 Missing whitespace around arithmetic operator
115 | #: E226
116 | c = (a + b)*(a - b)
|
= help: Add missing whitespace
E22.py:114:17: E226 Missing whitespace around arithmetic operator
Fix
111 111 | #: E226
112 112 | x = x/2 - 1
113 113 | #: E226 E226
114 |-hypot2 = x*x + y*y
114 |+hypot2 = x * x + y*y
115 115 | #: E226
116 116 | c = (a + b)*(a - b)
117 117 | #: E226
E22.py:114:17: E226 [*] Missing whitespace around arithmetic operator
|
112 | x = x/2 - 1
113 | #: E226 E226
@ -118,8 +490,19 @@ E22.py:114:17: E226 Missing whitespace around arithmetic operator
115 | #: E226
116 | c = (a + b)*(a - b)
|
= help: Add missing whitespace
E22.py:116:12: E226 Missing whitespace around arithmetic operator
Fix
111 111 | #: E226
112 112 | x = x/2 - 1
113 113 | #: E226 E226
114 |-hypot2 = x*x + y*y
114 |+hypot2 = x*x + y * y
115 115 | #: E226
116 116 | c = (a + b)*(a - b)
117 117 | #: E226
E22.py:116:12: E226 [*] Missing whitespace around arithmetic operator
|
114 | hypot2 = x*x + y*y
115 | #: E226
@ -128,8 +511,19 @@ E22.py:116:12: E226 Missing whitespace around arithmetic operator
117 | #: E226
118 | def halves(n):
|
= help: Add missing whitespace
E22.py:119:14: E226 Missing whitespace around arithmetic operator
Fix
113 113 | #: E226 E226
114 114 | hypot2 = x*x + y*y
115 115 | #: E226
116 |-c = (a + b)*(a - b)
116 |+c = (a + b) * (a - b)
117 117 | #: E226
118 118 | def halves(n):
119 119 | return (i//2 for i in range(n))
E22.py:119:14: E226 [*] Missing whitespace around arithmetic operator
|
117 | #: E226
118 | def halves(n):
@ -138,5 +532,16 @@ E22.py:119:14: E226 Missing whitespace around arithmetic operator
120 | #: E227
121 | _1kB = _1MB>>10
|
= help: Add missing whitespace
Fix
116 116 | c = (a + b)*(a - b)
117 117 | #: E226
118 118 | def halves(n):
119 |- return (i//2 for i in range(n))
119 |+ return (i // 2 for i in range(n))
120 120 | #: E227
121 121 | _1kB = _1MB>>10
122 122 | #: E227

View file

@ -1,7 +1,49 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E22.py:121:12: E227 Missing whitespace around bitwise or shift operator
E22.py:72:13: E227 [*] Missing whitespace around bitwise or shift operator
|
70 | z = (x + 1)** y
71 | #: E225
72 | _1kB = _1MB >>10
| ^^ E227
73 | #: E225
74 | _1kB = _1MB>> 10
|
= help: Add missing whitespace
Fix
69 69 | #: E225
70 70 | z = (x + 1)** y
71 71 | #: E225
72 |-_1kB = _1MB >>10
72 |+_1kB = _1MB >> 10
73 73 | #: E225
74 74 | _1kB = _1MB>> 10
75 75 | #: E225 E225
E22.py:74:12: E227 [*] Missing whitespace around bitwise or shift operator
|
72 | _1kB = _1MB >>10
73 | #: E225
74 | _1kB = _1MB>> 10
| ^^ E227
75 | #: E225 E225
76 | i=i+ 1
|
= help: Add missing whitespace
Fix
71 71 | #: E225
72 72 | _1kB = _1MB >>10
73 73 | #: E225
74 |-_1kB = _1MB>> 10
74 |+_1kB = _1MB >> 10
75 75 | #: E225 E225
76 76 | i=i+ 1
77 77 | #: E225 E225
E22.py:121:12: E227 [*] Missing whitespace around bitwise or shift operator
|
119 | return (i//2 for i in range(n))
120 | #: E227
@ -10,8 +52,19 @@ E22.py:121:12: E227 Missing whitespace around bitwise or shift operator
122 | #: E227
123 | _1MB = _1kB<<10
|
= help: Add missing whitespace
E22.py:123:12: E227 Missing whitespace around bitwise or shift operator
Fix
118 118 | def halves(n):
119 119 | return (i//2 for i in range(n))
120 120 | #: E227
121 |-_1kB = _1MB>>10
121 |+_1kB = _1MB >> 10
122 122 | #: E227
123 123 | _1MB = _1kB<<10
124 124 | #: E227
E22.py:123:12: E227 [*] Missing whitespace around bitwise or shift operator
|
121 | _1kB = _1MB>>10
122 | #: E227
@ -20,8 +73,19 @@ E22.py:123:12: E227 Missing whitespace around bitwise or shift operator
124 | #: E227
125 | a = b|c
|
= help: Add missing whitespace
E22.py:125:6: E227 Missing whitespace around bitwise or shift operator
Fix
120 120 | #: E227
121 121 | _1kB = _1MB>>10
122 122 | #: E227
123 |-_1MB = _1kB<<10
123 |+_1MB = _1kB << 10
124 124 | #: E227
125 125 | a = b|c
126 126 | #: E227
E22.py:125:6: E227 [*] Missing whitespace around bitwise or shift operator
|
123 | _1MB = _1kB<<10
124 | #: E227
@ -30,8 +94,19 @@ E22.py:125:6: E227 Missing whitespace around bitwise or shift operator
126 | #: E227
127 | b = c&a
|
= help: Add missing whitespace
E22.py:127:6: E227 Missing whitespace around bitwise or shift operator
Fix
122 122 | #: E227
123 123 | _1MB = _1kB<<10
124 124 | #: E227
125 |-a = b|c
125 |+a = b | c
126 126 | #: E227
127 127 | b = c&a
128 128 | #: E227
E22.py:127:6: E227 [*] Missing whitespace around bitwise or shift operator
|
125 | a = b|c
126 | #: E227
@ -40,8 +115,19 @@ E22.py:127:6: E227 Missing whitespace around bitwise or shift operator
128 | #: E227
129 | c = b^a
|
= help: Add missing whitespace
E22.py:129:6: E227 Missing whitespace around bitwise or shift operator
Fix
124 124 | #: E227
125 125 | a = b|c
126 126 | #: E227
127 |-b = c&a
127 |+b = c & a
128 128 | #: E227
129 129 | c = b^a
130 130 | #: E228
E22.py:129:6: E227 [*] Missing whitespace around bitwise or shift operator
|
127 | b = c&a
128 | #: E227
@ -50,5 +136,37 @@ E22.py:129:6: E227 Missing whitespace around bitwise or shift operator
130 | #: E228
131 | a = b%c
|
= help: Add missing whitespace
Fix
126 126 | #: E227
127 127 | b = c&a
128 128 | #: E227
129 |-c = b^a
129 |+c = b ^ a
130 130 | #: E228
131 131 | a = b%c
132 132 | #: E228
E22.py:154:11: E227 [*] Missing whitespace around bitwise or shift operator
|
152 | func2(lambda a, b=h[:], c=0: (a, b, c))
153 | if not -5 < x < +5:
154 | print >>sys.stderr, "x is out of range."
| ^^ E227
155 | print >> sys.stdout, "x is an integer."
156 | x = x / 2 - 1
|
= help: Add missing whitespace
Fix
151 151 | func1(lambda *args, **kw: (args, kw))
152 152 | func2(lambda a, b=h[:], c=0: (a, b, c))
153 153 | if not -5 < x < +5:
154 |- print >>sys.stderr, "x is out of range."
154 |+ print >> sys.stderr, "x is out of range."
155 155 | print >> sys.stdout, "x is an integer."
156 156 | x = x / 2 - 1
157 157 | x = 1 @ 2

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E22.py:131:6: E228 Missing whitespace around modulo operator
E22.py:131:6: E228 [*] Missing whitespace around modulo operator
|
129 | c = b^a
130 | #: E228
@ -10,8 +10,19 @@ E22.py:131:6: E228 Missing whitespace around modulo operator
132 | #: E228
133 | msg = fmt%(errno, errmsg)
|
= help: Add missing whitespace
E22.py:133:10: E228 Missing whitespace around modulo operator
Fix
128 128 | #: E227
129 129 | c = b^a
130 130 | #: E228
131 |-a = b%c
131 |+a = b % c
132 132 | #: E228
133 133 | msg = fmt%(errno, errmsg)
134 134 | #: E228
E22.py:133:10: E228 [*] Missing whitespace around modulo operator
|
131 | a = b%c
132 | #: E228
@ -20,8 +31,19 @@ E22.py:133:10: E228 Missing whitespace around modulo operator
134 | #: E228
135 | msg = "Error %d occurred"%errno
|
= help: Add missing whitespace
E22.py:135:26: E228 Missing whitespace around modulo operator
Fix
130 130 | #: E228
131 131 | a = b%c
132 132 | #: E228
133 |-msg = fmt%(errno, errmsg)
133 |+msg = fmt % (errno, errmsg)
134 134 | #: E228
135 135 | msg = "Error %d occurred"%errno
136 136 | #:
E22.py:135:26: E228 [*] Missing whitespace around modulo operator
|
133 | msg = fmt%(errno, errmsg)
134 | #: E228
@ -29,5 +51,16 @@ E22.py:135:26: E228 Missing whitespace around modulo operator
| ^ E228
136 | #:
|
= help: Add missing whitespace
Fix
132 132 | #: E228
133 133 | msg = fmt%(errno, errmsg)
134 134 | #: E228
135 |-msg = "Error %d occurred"%errno
135 |+msg = "Error %d occurred" % errno
136 136 | #:
137 137 |
138 138 | #: Okay