mirror of https://github.com/astral-sh/ruff
Only trigger compound statements after select keywords (#2737)
This commit is contained in:
parent
d2b09d77c5
commit
0bc1f68111
|
|
@ -21,5 +21,26 @@ def f(x): return 2*x
|
||||||
#: E704:2:5 E226:2:23
|
#: E704:2:5 E226:2:23
|
||||||
while all is round:
|
while all is round:
|
||||||
def f(x): return 2*x
|
def f(x): return 2*x
|
||||||
#:
|
#: E704:1:8 E702:1:11 E703:1:14
|
||||||
if True: x; y;
|
if True: x; y;
|
||||||
|
#: E701:1:8
|
||||||
|
if True: lambda a: b
|
||||||
|
#: E701:1:10
|
||||||
|
if a := 1: pass
|
||||||
|
# E701:1:4 E701:2:18 E701:3:8
|
||||||
|
try: lambda foo: bar
|
||||||
|
except ValueError: pass
|
||||||
|
finally: pass
|
||||||
|
# E701:1:7
|
||||||
|
class C: pass
|
||||||
|
# E701:1:7
|
||||||
|
with C(): pass
|
||||||
|
# E701:1:14
|
||||||
|
async with C(): pass
|
||||||
|
#:
|
||||||
|
lambda a: b
|
||||||
|
#:
|
||||||
|
a: List[str] = []
|
||||||
|
#:
|
||||||
|
if a := 1:
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,16 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
let mut def = None;
|
let mut def = None;
|
||||||
let mut colon = None;
|
let mut colon = None;
|
||||||
let mut semi = None;
|
let mut semi = None;
|
||||||
|
let mut class = None;
|
||||||
|
let mut elif = None;
|
||||||
|
let mut else_ = None;
|
||||||
|
let mut except = None;
|
||||||
|
let mut finally = None;
|
||||||
|
let mut for_ = None;
|
||||||
|
let mut if_ = None;
|
||||||
|
let mut try_ = None;
|
||||||
|
let mut while_ = None;
|
||||||
|
let mut with = None;
|
||||||
|
|
||||||
// Track the bracket depth.
|
// Track the bracket depth.
|
||||||
let mut par_count = 0;
|
let mut par_count = 0;
|
||||||
|
|
@ -96,12 +106,35 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
def = None;
|
def = None;
|
||||||
colon = None;
|
colon = None;
|
||||||
semi = None;
|
semi = None;
|
||||||
|
class = None;
|
||||||
|
elif = None;
|
||||||
|
else_ = None;
|
||||||
|
except = None;
|
||||||
|
finally = None;
|
||||||
|
for_ = None;
|
||||||
|
if_ = None;
|
||||||
|
try_ = None;
|
||||||
|
while_ = None;
|
||||||
|
with = None;
|
||||||
}
|
}
|
||||||
Tok::Def => {
|
Tok::Def => {
|
||||||
def = Some((start, end));
|
def = Some((start, end));
|
||||||
}
|
}
|
||||||
Tok::Colon => {
|
Tok::Colon => {
|
||||||
colon = Some((start, end));
|
if def.is_some()
|
||||||
|
|| class.is_some()
|
||||||
|
|| elif.is_some()
|
||||||
|
|| else_.is_some()
|
||||||
|
|| except.is_some()
|
||||||
|
|| finally.is_some()
|
||||||
|
|| for_.is_some()
|
||||||
|
|| if_.is_some()
|
||||||
|
|| try_.is_some()
|
||||||
|
|| while_.is_some()
|
||||||
|
|| with.is_some()
|
||||||
|
{
|
||||||
|
colon = Some((start, end));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Tok::Semi => {
|
Tok::Semi => {
|
||||||
semi = Some((start, end));
|
semi = Some((start, end));
|
||||||
|
|
@ -134,9 +167,53 @@ pub fn compound_statements(lxr: &[LexResult]) -> Vec<Diagnostic> {
|
||||||
// Reset.
|
// Reset.
|
||||||
def = None;
|
def = None;
|
||||||
colon = None;
|
colon = None;
|
||||||
|
class = None;
|
||||||
|
elif = None;
|
||||||
|
else_ = None;
|
||||||
|
except = None;
|
||||||
|
finally = None;
|
||||||
|
for_ = None;
|
||||||
|
if_ = None;
|
||||||
|
try_ = None;
|
||||||
|
while_ = None;
|
||||||
|
with = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match tok {
|
||||||
|
Tok::If => {
|
||||||
|
if_ = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::While => {
|
||||||
|
while_ = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::For => {
|
||||||
|
for_ = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::Try => {
|
||||||
|
try_ = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::Except => {
|
||||||
|
except = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::Finally => {
|
||||||
|
finally = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::Elif => {
|
||||||
|
elif = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::Else => {
|
||||||
|
else_ = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::Class => {
|
||||||
|
class = Some((start, end));
|
||||||
|
}
|
||||||
|
Tok::With => {
|
||||||
|
with = Some((start, end));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
diagnostics
|
diagnostics
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,84 @@ expression: diagnostics
|
||||||
column: 8
|
column: 8
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 27
|
||||||
|
column: 7
|
||||||
|
end_location:
|
||||||
|
row: 27
|
||||||
|
column: 8
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 29
|
||||||
|
column: 9
|
||||||
|
end_location:
|
||||||
|
row: 29
|
||||||
|
column: 10
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 31
|
||||||
|
column: 3
|
||||||
|
end_location:
|
||||||
|
row: 31
|
||||||
|
column: 4
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 32
|
||||||
|
column: 17
|
||||||
|
end_location:
|
||||||
|
row: 32
|
||||||
|
column: 18
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 33
|
||||||
|
column: 7
|
||||||
|
end_location:
|
||||||
|
row: 33
|
||||||
|
column: 8
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 35
|
||||||
|
column: 7
|
||||||
|
end_location:
|
||||||
|
row: 35
|
||||||
|
column: 8
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 37
|
||||||
|
column: 8
|
||||||
|
end_location:
|
||||||
|
row: 37
|
||||||
|
column: 9
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
- kind:
|
||||||
|
MultipleStatementsOnOneLineColon: ~
|
||||||
|
location:
|
||||||
|
row: 39
|
||||||
|
column: 14
|
||||||
|
end_location:
|
||||||
|
row: 39
|
||||||
|
column: 15
|
||||||
|
fix: ~
|
||||||
|
parent: ~
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue