-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add manual_empty_string_creations
lint
#9295
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
Add manual_empty_string_creations
lint
#9295
Conversation
r? @dswij (rust-highfive has picked a reviewer for you, use r? to override) |
c2e205d
to
0331eec
Compare
☔ The latest upstream changes (presumably #9288) made this pull request unmergeable. Please resolve the merge conflicts. |
a51c778
to
5de73c8
Compare
"empty String is being created manually", | ||
"consider using", | ||
"String::new()".into(), | ||
Unspecified, |
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.
Why not make this MachineApplicable?
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.
I was a little bit unsure if this new lint can have false positives. Do you think it seems safe to make it MachineApplicable
?
It worked fine in clippy's codebase, but since I'm still unexperienced with these lints I'm not sure.
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.
IMO, machine applicable suggestions won't make the false positives any more annoying but it will allow people to use Cargo fix.
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.
I don't see how the suggestions can go really wrong with this lint. Making it machine applicable seems fine, the lint will still trigger in FP cases either way.
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 for the suggestions! Fixed in 4e9aebfbd2b9b94b08d27f0d61ea47d8e9e80633
It looks like this lint needs a macro check. Here is a false positive from clap.
|
5de73c8
to
089f2d0
Compare
Thanks for catching this! I thought checking for external macros would be enough, but it seems that is not the case. Fixed in 4e9aebf |
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 for the PR! The lint itself looks great.
- Clippy prefers plural lint names. Can you help to rename the lint with plural form? i.e.
manual_empty_string_creations
. - Can we add a test case covering the macro scenario?
089f2d0
to
a1dd064
Compare
manual_empty_string_creation
lintmanual_empty_string_creations
lint
a1dd064
to
c200bd3
Compare
c200bd3
to
1bf8841
Compare
@Guilherme-Vasconcelos Huge thanks for this! This lint is certainly nice to have. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Rename `manual_empty_string_creation` and move to pedantic Renames it to `manual_string_new` and moves it to the pedantic category Pedantic because it's a fairly minor style change but could be very noisy changelog: *doesn't need its own entry, but remember to s/manual_empty_string_creation/manual_string_new/ the changelog entry for #9295* r? `@xFrednet` to get it in before the upcoming sync as this isn't a `cargo dev rename_lint` style rename
Closes #2972
.stderr
file)cargo test
passes locallycargo dev update_lints
cargo dev fmt
changelog: [
manual_empty_string_creations
]: Add lint for empty String not being created withString::new()