mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 16:10:17 +00:00
[flake8-simplify
] Implement enumerate-for-loop
(SIM113
) (#7777)
Implements SIM113 from #998 Added tests Limitations - No fix yet - Only flag cases where index variable immediately precede `for` loop @charliermarsh please review and let me know any improvements --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
parent
b6ce4f5f3a
commit
0003c730e0
14 changed files with 464 additions and 11 deletions
|
@ -79,3 +79,15 @@ pub fn next_sibling<'a>(stmt: &'a Stmt, suite: &'a Suite) -> Option<&'a Stmt> {
|
|||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Given a [`Stmt`] and its containing [`Suite`], return the previous [`Stmt`] in the [`Suite`].
|
||||
pub fn prev_sibling<'a>(stmt: &'a Stmt, suite: &'a Suite) -> Option<&'a Stmt> {
|
||||
let mut prev = None;
|
||||
for sibling in suite {
|
||||
if sibling == stmt {
|
||||
return prev;
|
||||
}
|
||||
prev = Some(sibling);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue