Skip to content

Commit

Permalink
E203: Don't warn about single whitespace before tuple ,
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Feb 23, 2024
1 parent 8c20f14 commit 80ac3d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 6 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@

#: E203:1:10
ham[upper :]

#: Okay
ham[lower +1 :, "columnname"]

#: E203:1:13
ham[lower + 1 :, "columnname"]
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ pub(crate) fn extraneous_whitespace(line: &LogicalLine, context: &mut LogicalLin
// equivalent spacing on both sides, allow it.
if symbol == ':'
&& brackets
.last()
.is_some_and(|kind| matches!(kind, TokenKind::Lsqb))
.last()
.is_some_and(|kind| matches!(kind, TokenKind::Lsqb))
{
// If we're in the second half of a double colon, disallow
// any whitespace (e.g., `foo[1: :2]` or `foo[1 : : 2]`).
Expand All @@ -213,11 +213,11 @@ pub(crate) fn extraneous_whitespace(line: &LogicalLine, context: &mut LogicalLin
diagnostic.range(),
)));
context.push_diagnostic(diagnostic);
} else if iter
.peek()
.is_some_and(|token| token.kind() == TokenKind::Rsqb)
{
} else if iter.peek().is_some_and(|token| {
matches!(token.kind(), TokenKind::Rsqb | TokenKind::Comma)
}) {
// Allow `foo[1 :]`, but not `foo[1 :]`.
// Or `foo[index :, 2]`, but not `foo[index :, 2]`.
if let (Whitespace::Many | Whitespace::Tab, offset) = whitespace
{
let mut diagnostic = Diagnostic::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ E20.py:149:10: E203 [*] Whitespace before ':'
148 | #: E203:1:10
149 | ham[upper :]
| ^^ E203
150 |
151 | #: Okay
|
= help: Remove whitespace before ':'

Expand All @@ -240,5 +242,21 @@ E20.py:149:10: E203 [*] Whitespace before ':'
148 148 | #: E203:1:10
149 |-ham[upper :]
149 |+ham[upper:]
150 150 |
151 151 | #: Okay
152 152 | ham[lower +1 :, "columnname"]

E20.py:155:14: E203 [*] Whitespace before ':'
|
154 | #: E203:1:13
155 | ham[lower + 1 :, "columnname"]
| ^^ E203
|
= help: Remove whitespace before ':'

Safe fix
152 152 | ham[lower +1 :, "columnname"]
153 153 |
154 154 | #: E203:1:13
155 |-ham[lower + 1 :, "columnname"]
155 |+ham[lower + 1:, "columnname"]

0 comments on commit 80ac3d4

Please sign in to comment.