diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E26.py b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E26.py index 9d35553dc5..51048adc7c 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E26.py +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E26.py @@ -72,3 +72,8 @@ a = 42 # (Two spaces) # EF Means test is giving error and Failing #! Means test is segfaulting # 8 Means test runs forever + +#%% +# %% +# This is a comment +# This is another comment diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs index 366fc675b2..0ff3a484e8 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_comment.rs @@ -167,10 +167,10 @@ pub(crate) fn whitespace_before_comment( let symbol = parts.next().unwrap_or(""); let comment = parts.next().unwrap_or(""); - let bad_prefix = if symbol != "#" && symbol != "#:" { - Some(symbol.trim_start_matches('#').chars().next().unwrap_or('#')) - } else { + let bad_prefix = if matches!(symbol, "#" | "#:" | "#!" | "#%%") { None + } else { + Some(symbol.trim_start_matches('#').chars().next().unwrap_or('#')) }; if is_inline_comment { diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E265_E26.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E265_E26.py.snap index 6017827141..0b041013aa 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E265_E26.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E265_E26.py.snap @@ -11,16 +11,6 @@ E26.py:10:1: E265 Block comment should start with `# ` 12 | #: E265:2:1 | -E26.py:14:1: E265 Block comment should start with `# ` - | -12 | #: E265:2:1 -13 | m = 42 -14 | #! This is important - | ^^^^^^^^^^^^^^^^^^^^ E265 -15 | mx = 42 - 42 -16 | #: E266:3:5 E266:6:5 - | - E26.py:25:1: E265 Block comment should start with `# ` | 23 | return @@ -40,13 +30,4 @@ E26.py:32:1: E265 Block comment should start with `# ` 34 | pass # an inline comment | -E26.py:73:1: E265 Block comment should start with `# ` - | -71 | # F Means test is failing (F) -72 | # EF Means test is giving error and Failing -73 | #! Means test is segfaulting - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E265 -74 | # 8 Means test runs forever - | - diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__shebang.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__shebang.snap index 63d5b9fefc..6dcc4546f1 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__shebang.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__shebang.snap @@ -1,13 +1,4 @@ --- source: crates/ruff_linter/src/rules/pycodestyle/mod.rs --- -shebang.py:3:1: E265 Block comment should start with `# ` - | -1 | #!/usr/bin/python -2 | # -3 | #! - | ^^ E265 -4 | #: - | -