[refurb] Implement slice-to-remove-prefix-or-suffix (FURB188)#13256
[refurb] Implement slice-to-remove-prefix-or-suffix (FURB188)#13256AlexWaygood merged 26 commits intoastral-sh:mainfrom
slice-to-remove-prefix-or-suffix (FURB188)#13256Conversation
|
Not super happy with how gnarly the implementation is - so open to any feedback/tips to clean it up. I've tried to add comments wherever possible so hopefully it is at least readable. Definitely found myself wishing that Rust supported matching patterns involving structs with heavily nested |
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| FURB188 | 7 | 7 | 0 | 0 | 0 |
AlexWaygood
left a comment
There was a problem hiding this comment.
Nice! I can see that a lot of work went into this
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Show resolved
Hide resolved
MichaReiser
left a comment
There was a problem hiding this comment.
I only skimmed over the rust code and left a few NIT comments.
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
|
Wow @AlexWaygood and @MichaReiser - what a fantastic and thorough code review! Thanks so much! Learning a lot from you |
AlexWaygood
left a comment
There was a problem hiding this comment.
Very nice indeed! Basically just nits remaining, though there is one other location where I think you should use match_builtin_expr() for correctness
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/refurb/rules/slice_to_remove_prefix_or_suffix.rs
Show resolved
Hide resolved
|
Thanks again! I think I picked the remaining nits. |
AlexWaygood
left a comment
There was a problem hiding this comment.
Fab! Some tiny last remaining comments:
This PR implements
FURB188which suggests the use ofremoveprefix/removesuffixin order to remove prefixes and suffixes from strings, rather than slicing the string conditionally upon the output ofstartswith/endswith.Tested using same test suite as
refurb.Moves the needle on #1348.