diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py index 2817f2ef9b6f8..01d49e2930c51 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E20.py @@ -153,3 +153,9 @@ #: E203:1:13 ham[lower + 1 :, "columnname"] + +#: Okay +f"{ham[lower +1 :, "columnname"]}" + +#: E203:1:13 +f"{ham[lower + 1 :, "columnname"]}" diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs index 3f568cf99dc06..216592973e67d 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs @@ -137,16 +137,16 @@ pub(crate) fn extraneous_whitespace(line: &LogicalLine, context: &mut LogicalLin match kind { TokenKind::FStringStart => fstrings += 1, TokenKind::FStringEnd => fstrings = fstrings.saturating_sub(1), - TokenKind::Lsqb if fstrings == 0 => { + TokenKind::Lsqb => { brackets.push(kind); } - TokenKind::Rsqb if fstrings == 0 => { + TokenKind::Rsqb => { brackets.pop(); } - TokenKind::Lbrace if fstrings == 0 => { + TokenKind::Lbrace => { brackets.push(kind); } - TokenKind::Rbrace if fstrings == 0 => { + TokenKind::Rbrace => { brackets.pop(); } _ => {} diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E203_E20.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E203_E20.py.snap index 01c7ebc0713f6..c70c11d79c8ba 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E203_E20.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E203_E20.py.snap @@ -251,6 +251,8 @@ E20.py:155:14: E203 [*] Whitespace before ':' 154 | #: E203:1:13 155 | ham[lower + 1 :, "columnname"] | ^^ E203 +156 | +157 | #: Okay | = help: Remove whitespace before ':' @@ -260,3 +262,21 @@ E20.py:155:14: E203 [*] Whitespace before ':' 154 154 | #: E203:1:13 155 |-ham[lower + 1 :, "columnname"] 155 |+ham[lower + 1:, "columnname"] +156 156 | +157 157 | #: Okay +158 158 | f"{ham[lower +1 :, "columnname"]}" + +E20.py:161:17: E203 [*] Whitespace before ':' + | +160 | #: E203:1:13 +161 | f"{ham[lower + 1 :, "columnname"]}" + | ^^ E203 + | + = help: Remove whitespace before ':' + +ℹ Safe fix +158 158 | f"{ham[lower +1 :, "columnname"]}" +159 159 | +160 160 | #: E203:1:13 +161 |-f"{ham[lower + 1 :, "columnname"]}" + 161 |+f"{ham[lower + 1:, "columnname"]}"