-
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
[refurb
] New rule to suggest min/max over sorted() (FURB192
)
#10868
[refurb
] New rule to suggest min/max over sorted() (FURB192
)
#10868
Conversation
@@ -3075,6 +3075,8 @@ | |||
"FURB180", | |||
"FURB181", | |||
"FURB187", | |||
"FURB19", |
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.
This auto-generated FURB19
but I can't figure out why
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
FURB192 | 4 | 4 | 0 | 0 | 0 |
I'd definitely advocate for making unstable sort fixes unsafe. Otherwise, it could unknowingly change user code. I'd also argue we may want add to add a config option for this rule that ignores unstable sorts. |
|
||
let replacement = if let Some(key) = &key_keyword_expr { | ||
format!( | ||
"{}({}, key={})", |
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.
Is there a cleaner or more canonical way to generate this?
Agreed, and updated!
Shall I do this too? Haven't heard anyone else chime in yet. |
CodSpeed Performance ReportMerging #10868 will not alter performanceComparing Summary
|
I probably wouldn't implement it now since the rule is just going into preview. We can use preview feedback to consider adding an option. I'd just open a tracking issue when this is merged. |
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!
Summary
Fixes #10463
Add
FURB192
which detects violations like this:There is a caveat that @Skylion007 has pointed out, which is that violations with
reverse=True
technically aren't compatible with this change, in the edge case where the unstable behavior is intended. For example:This seems like a rare edge case, but I can make the
reverse=True
fixes unsafe if that's best.Test Plan
This is unit tested.
References
https://github.com/dosisod/refurb/pull/333/files