diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E23.py b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E23.py index 4d0089bb451ab..2d7e70e99d4ac 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E23.py +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E23.py @@ -40,5 +40,11 @@ def foo() -> None: f"{(lambda x:x)}" f"normal{f"{a:.3f}"}normal" +#: Okay +snapshot.file_uri[len(f's3://{self.s3_bucket_name}/'):] + +#: E231 +{len(f's3://{self.s3_bucket_name}/'):1} + #: Okay a = (1, diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs index 314693446aa86..2da0664dc7ead 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs @@ -64,14 +64,14 @@ pub(crate) fn missing_whitespace(line: &LogicalLine, context: &mut LogicalLinesC match kind { TokenKind::FStringStart => fstrings += 1, TokenKind::FStringEnd => fstrings = fstrings.saturating_sub(1), - TokenKind::Lsqb => { + TokenKind::Lsqb if fstrings == 0 => { open_parentheses = open_parentheses.saturating_add(1); prev_lsqb = token.start(); } - TokenKind::Rsqb => { + TokenKind::Rsqb if fstrings == 0 => { open_parentheses = open_parentheses.saturating_sub(1); } - TokenKind::Lbrace => { + TokenKind::Lbrace if fstrings == 0 => { prev_lbrace = token.start(); } TokenKind::Colon if fstrings > 0 => { diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E231_E23.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E231_E23.py.snap index d0839a77a266f..e8e3663c82d52 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E231_E23.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E231_E23.py.snap @@ -121,4 +121,24 @@ E23.py:33:6: E231 [*] Missing whitespace after ',' 35 35 | # Okay because it's hard to differentiate between the usages of a colon in a f-string 36 36 | f"{a:=1}" +E23.py:47:37: E231 [*] Missing whitespace after ':' + | +46 | #: E231 +47 | {len(f's3://{self.s3_bucket_name}/'):1} + | ^ E231 +48 | +49 | #: Okay + | + = help: Add missing whitespace + +ℹ Fix +44 44 | snapshot.file_uri[len(f's3://{self.s3_bucket_name}/'):] +45 45 | +46 46 | #: E231 +47 |-{len(f's3://{self.s3_bucket_name}/'):1} + 47 |+{len(f's3://{self.s3_bucket_name}/'): 1} +48 48 | +49 49 | #: Okay +50 50 | a = (1, +