mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Fix allowed-ellipsis detection (#5174)
## Summary We weren't resetting the `allow_ellipsis` flag properly, which ultimately caused us to treat the semicolon as "unnecessary" rather than "creating a multi-statement line". Closes #5154.
This commit is contained in:
parent
2b82caa163
commit
be11cae619
3 changed files with 20 additions and 5 deletions
|
@ -60,3 +60,6 @@ match *0, 1, *2:
|
||||||
#:
|
#:
|
||||||
class Foo:
|
class Foo:
|
||||||
match: Optional[Match] = None
|
match: Optional[Match] = None
|
||||||
|
#: E702:2:4
|
||||||
|
while 1:
|
||||||
|
1;...
|
||||||
|
|
|
@ -145,6 +145,12 @@ pub(crate) fn compound_statements(lxr: &[LexResult], settings: &Settings) -> Vec
|
||||||
Tok::Rbrace => {
|
Tok::Rbrace => {
|
||||||
brace_count = brace_count.saturating_sub(1);
|
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()
|
|| with.is_some()
|
||||||
{
|
{
|
||||||
colon = Some((range.start(), range.end()));
|
colon = Some((range.start(), range.end()));
|
||||||
allow_ellipsis = true;
|
|
||||||
|
// Allow `class C: ...`-style definitions in stubs.
|
||||||
|
allow_ellipsis = class.is_some();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tok::Semi => {
|
Tok::Semi => {
|
||||||
semi = Some((range.start(), range.end()));
|
semi = Some((range.start(), range.end()));
|
||||||
}
|
}
|
||||||
Tok::Comment(..) | Tok::Indent | Tok::Dedent | Tok::NonLogicalNewline => {}
|
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 {
|
if let Some((start, end)) = semi {
|
||||||
diagnostics.push(Diagnostic::new(
|
diagnostics.push(Diagnostic::new(
|
||||||
|
|
|
@ -61,4 +61,12 @@ E70.py:56:13: E702 Multiple statements on one line (semicolon)
|
||||||
58 | match *0, 1, *2:
|
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
|
||||||
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue