Skip to content

Commit

Permalink
E203: Don't warn about single whitespace before tuple , (astral-sh#10094
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MichaReiser authored and nkxxll committed Mar 4, 2024
1 parent fc2e637 commit cb1fcf1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 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 @@ -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 cb1fcf1

Please sign in to comment.