[refurb] New rule to suggest min/max over sorted() (FURB192)#10868
[refurb] New rule to suggest min/max over sorted() (FURB192)#10868charliermarsh merged 32 commits intoastral-sh:mainfrom
refurb] New rule to suggest min/max over sorted() (FURB192)#10868Conversation
| "FURB180", | ||
| "FURB181", | ||
| "FURB187", | ||
| "FURB19", |
There was a problem hiding this comment.
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.
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. |
Summary
Fixes #10463
Add
FURB192which detects violations like this:There is a caveat that @Skylion007 has pointed out, which is that violations with
reverse=Truetechnically 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=Truefixes unsafe if that's best.Test Plan
This is unit tested.
References
https://github.com/dosisod/refurb/pull/333/files