diff --git a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E70.py b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E70.py index 861a99cb9dd91..45d1941d22cb1 100644 --- a/crates/ruff_linter/resources/test/fixtures/pycodestyle/E70.py +++ b/crates/ruff_linter/resources/test/fixtures/pycodestyle/E70.py @@ -69,3 +69,5 @@ class Foo: #: E701:2:3 a = \ 5; +#: +with x(y) as z: ... diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs index a8c8dd3d287b1..6dcdd19c8b4ec 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs @@ -24,7 +24,7 @@ use ruff_source_file::Locator; /// if foo == "blah": /// do_blah_thing() /// ``` - +/// /// [PEP 8]: https://peps.python.org/pep-0008/#other-recommendations #[violation] pub struct MultipleStatementsOnOneLineColon; @@ -206,12 +206,13 @@ pub(crate) fn compound_statements( { colon = Some((range.start(), range.end())); - // Allow `class C: ...`-style definitions in stubs. - allow_ellipsis = class.is_some(); + // Allow `class C: ...`-style definitions. + allow_ellipsis = true; } } Tok::Semi => { semi = Some((range.start(), range.end())); + allow_ellipsis = false; } Tok::Comment(..) | Tok::Indent | Tok::Dedent | Tok::NonLogicalNewline => {} _ => { @@ -223,6 +224,7 @@ pub(crate) fn compound_statements( // Reset. semi = None; + allow_ellipsis = false; } if let Some((start, end)) = colon { @@ -245,6 +247,7 @@ pub(crate) fn compound_statements( try_ = None; while_ = None; with = None; + allow_ellipsis = false; } } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E703_E70.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E703_E70.py.snap index 798febf2364a0..3d3c378dcc314 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E703_E70.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E703_E70.py.snap @@ -92,6 +92,8 @@ E70.py:71:4: E703 [*] Statement ends with an unnecessary semicolon 70 | a = \ 71 | 5; | ^ E703 +72 | #: +73 | with x(y) as z: ... | = help: Remove unnecessary semicolon @@ -101,5 +103,7 @@ E70.py:71:4: E703 [*] Statement ends with an unnecessary semicolon 70 70 | a = \ 71 |- 5; 71 |+ 5 +72 72 | #: +73 73 | with x(y) as z: ...