diff --git a/crates/ruff/resources/test/fixtures/pycodestyle/E70.py b/crates/ruff/resources/test/fixtures/pycodestyle/E70.py index bfbec79124..2fa6fa4813 100644 --- a/crates/ruff/resources/test/fixtures/pycodestyle/E70.py +++ b/crates/ruff/resources/test/fixtures/pycodestyle/E70.py @@ -60,3 +60,6 @@ match *0, 1, *2: #: class Foo: match: Optional[Match] = None +#: E702:2:4 +while 1: + 1;... diff --git a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs index 6f095d8272..fd9b57b6e9 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/compound_statements.rs @@ -145,6 +145,12 @@ pub(crate) fn compound_statements(lxr: &[LexResult], settings: &Settings) -> Vec Tok::Rbrace => { brace_count = brace_count.saturating_sub(1); } + Tok::Ellipsis => { + if allow_ellipsis { + allow_ellipsis = false; + continue; + } + } _ => {} } @@ -195,17 +201,15 @@ pub(crate) fn compound_statements(lxr: &[LexResult], settings: &Settings) -> Vec || with.is_some() { colon = Some((range.start(), range.end())); - allow_ellipsis = true; + + // Allow `class C: ...`-style definitions in stubs. + allow_ellipsis = class.is_some(); } } Tok::Semi => { semi = Some((range.start(), range.end())); } Tok::Comment(..) | Tok::Indent | Tok::Dedent | Tok::NonLogicalNewline => {} - Tok::Ellipsis if allow_ellipsis => { - // Allow `class C: ...`-style definitions in stubs. - allow_ellipsis = false; - } _ => { if let Some((start, end)) = semi { diagnostics.push(Diagnostic::new( diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap index 5bca9b1e53..20d62cd44b 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap @@ -61,4 +61,12 @@ E70.py:56:13: E702 Multiple statements on one line (semicolon) 58 | match *0, 1, *2: | +E70.py:65:4: E702 Multiple statements on one line (semicolon) + | +63 | #: E702:2:4 +64 | while 1: +65 | 1;... + | ^ E702 + | +