Skip to content

Commit 72c18c8

Browse files
authored
Fix E221 and E222 to flag missing or extra whitespace around == operator (#13890)
1 parent 00b0782 commit 72c18c8

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

crates/ruff_linter/resources/test/fixtures/pycodestyle/E22.py

+3
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,6 @@ def squares(n):
180180
if i == -1:
181181
pass
182182
#:
183+
184+
if a == 1:
185+
print(a)

crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/space_around_operator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ const fn is_operator_token(token: TokenKind) -> bool {
302302
| TokenKind::Equal
303303
| TokenKind::Percent
304304
| TokenKind::NotEqual
305+
| TokenKind::EqEqual
305306
| TokenKind::LessEqual
306307
| TokenKind::GreaterEqual
307308
| TokenKind::CircumFlex

crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E221_E22.py.snap

+16
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,20 @@ E22.py:19:14: E221 [*] Multiple spaces before operator
168168
21 21 | x = 1
169169
22 22 | y = 2
170170

171+
E22.py:184:5: E221 [*] Multiple spaces before operator
172+
|
173+
182 | #:
174+
183 |
175+
184 | if a == 1:
176+
| ^^ E221
177+
185 | print(a)
178+
|
179+
= help: Replace with single space
171180

181+
Safe fix
182+
181 181 | pass
183+
182 182 | #:
184+
183 183 |
185+
184 |-if a == 1:
186+
184 |+if a == 1:
187+
185 185 | print(a)

crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E222_E22.py.snap

+16
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,20 @@ E22.py:36:7: E222 [*] Multiple spaces after operator
105105
38 38 | #:
106106
39 39 |
107107

108+
E22.py:184:9: E222 [*] Multiple spaces after operator
109+
|
110+
182 | #:
111+
183 |
112+
184 | if a == 1:
113+
| ^^ E222
114+
185 | print(a)
115+
|
116+
= help: Replace with single space
108117

118+
Safe fix
119+
181 181 | pass
120+
182 182 | #:
121+
183 183 |
122+
184 |-if a == 1:
123+
184 |+if a == 1:
124+
185 185 | print(a)

0 commit comments

Comments
 (0)