Skip to content

Commit d068e8f

Browse files
committed
E203: Don't warn about single whitespace before tuple ,
1 parent 8c20f14 commit d068e8f

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,9 @@
147147

148148
#: E203:1:10
149149
ham[upper :]
150+
151+
#: Okay
152+
ham[lower +1 :, "columnname"]
153+
154+
#: E203:1:13
155+
ham[lower + 1 :, "columnname"]

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ pub(crate) fn extraneous_whitespace(line: &LogicalLine, context: &mut LogicalLin
213213
diagnostic.range(),
214214
)));
215215
context.push_diagnostic(diagnostic);
216-
} else if iter
217-
.peek()
218-
.is_some_and(|token| token.kind() == TokenKind::Rsqb)
219-
{
216+
} else if iter.peek().is_some_and(|token| {
217+
matches!(token.kind(), TokenKind::Rsqb | TokenKind::Comma)
218+
}) {
220219
// Allow `foo[1 :]`, but not `foo[1 :]`.
220+
// Or `foo[index :, 2]`, but not `foo[index :, 2]`.
221221
if let (Whitespace::Many | Whitespace::Tab, offset) = whitespace
222222
{
223223
let mut diagnostic = Diagnostic::new(

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

+18
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ E20.py:149:10: E203 [*] Whitespace before ':'
231231
148 | #: E203:1:10
232232
149 | ham[upper :]
233233
| ^^ E203
234+
150 |
235+
151 | #: Okay
234236
|
235237
= help: Remove whitespace before ':'
236238

@@ -240,5 +242,21 @@ E20.py:149:10: E203 [*] Whitespace before ':'
240242
148 148 | #: E203:1:10
241243
149 |-ham[upper :]
242244
149 |+ham[upper:]
245+
150 150 |
246+
151 151 | #: Okay
247+
152 152 | ham[lower +1 :, "columnname"]
243248

249+
E20.py:155:14: E203 [*] Whitespace before ':'
250+
|
251+
154 | #: E203:1:13
252+
155 | ham[lower + 1 :, "columnname"]
253+
| ^^ E203
254+
|
255+
= help: Remove whitespace before ':'
244256

257+
Safe fix
258+
152 152 | ham[lower +1 :, "columnname"]
259+
153 153 |
260+
154 154 | #: E203:1:13
261+
155 |-ham[lower + 1 :, "columnname"]
262+
155 |+ham[lower + 1:, "columnname"]

0 commit comments

Comments
 (0)