[flake8-simplify] Detect implicit else cases in needless-bool (SIM103)#10414
Conversation
.../flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM103_SIM103.py.snap
Outdated
Show resolved
Hide resolved
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM103 | 156 | 156 | 0 | 0 | 0 |
|
Thanks! Do you mind moving this to preview-only?
Yes, the best prior art here would be... let parent = checker.semantic().current_statement_parent()?;
let suite = traversal::suite(stmt, parent)?;
let sibling = traversal::next_sibling(stmt, suite)?;So, ideally, we check if the statement is an |
Yep! Is there a way to partially move (Flake8Simplify, "103") => (RuleGroup::Stable, rules::flake8_simplify::rules::NeedlessBool),
Ah, I'll refactor to use that instead! |
So typically we'd just add a check for the new codepath on |
CodSpeed Performance ReportMerging #10414 will not alter performanceComparing Summary
|
|
Ready for another review @charliermarsh . Thanks for the help!
|
|
Looks like my clone() is slowing down perf tests. I'll look into that. |
crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs
Outdated
Show resolved
Hide resolved
| ( | ||
| if_test.as_ref(), | ||
| if_body, | ||
| std::slice::from_ref(next_stmt), |
There was a problem hiding this comment.
@ottaviohartman -- I was able to remove the vector allocation here by making every branch return &[Stmt] instead of &Vec<Stmt>. Then, you can do a nice trick whereby if you have an &T, you can create &[T] via std::slice::from_ref.
There was a problem hiding this comment.
Awesome - I'll use that in the future.
SIM103 detect implicit elseflake8-simplify] Detect implicit else cases in needless-bool (SIM103)
Fixes #10402
Summary
For SIM103, detect and simplify the following case:
playground link
Test Plan
Unit tested only.