[ruff] Implement falsy-dict-get-fallback (RUF056)#15160
[ruff] Implement falsy-dict-get-fallback (RUF056)#15160MichaReiser merged 9 commits intoastral-sh:mainfrom
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. |
MichaReiser
left a comment
There was a problem hiding this comment.
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.