-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-simplify
] Detect implicit else
cases in needless-bool
(SIM103
)
#10414
[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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
( | ||
if_test.as_ref(), | ||
if_body, | ||
std::slice::from_ref(next_stmt), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome - I'll use that in the future.
SIM103
detect implicit else
flake8-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.