-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[ruff] Implement falsy-dict-get-fallback (RUF056) #15160
[ruff] Implement falsy-dict-get-fallback (RUF056) #15160
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF056 | 40 | 40 | 0 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
Went through all 40 ecosystem linter changes, all are as expected. |
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.
Nice thank you. I think we can reuse some existing helpers to remove the necessary code for this rule
crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/falsy_dict_get_fallback.rs
Outdated
Show resolved
Hide resolved
…k.rs Co-authored-by: Micha Reiser <micha@reiser.io>
Summary
Closes #4934 by implementing a new RUF rule that checks for dict.get calls that include a falsy fallback used in the context of a boolean, and returns a safe fix that removes that falsy fallback (except for situations where there are comments between arguments, in which case an unsafe fix is returned).
Note, using a falsy fallback for dict.get is okay when the expression is not used as a boolean, e.g. when the the actual value of the fallback is used instead of being converted to a boolean.
Test Plan
A RUF056.py snapshot test file was created that includes valid and invalid code based on this lint rule.