Skip to content

Adding feature to "accept" a clippy suggestion #4300

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Will-Low opened this issue Jul 25, 2019 · 2 comments
Closed

Adding feature to "accept" a clippy suggestion #4300

Will-Low opened this issue Jul 25, 2019 · 2 comments

Comments

@Will-Low
Copy link

Will-Low commented Jul 25, 2019

Clippy has some great suggestions that contain working code, like the message below:

   --> src/data_types.rs:143:63
    |
143 |                   hashed_conditions.get(&condition.description).expect(
    |  _______________________________________________________________^
144 | |                     format!(
145 | |                         "[ERROR] condition in play \"{}\" not found in \"conditions.yaml\".",
146 | |                         &condition.description
147 | |                     )
148 | |                     .as_str(),
149 | |                 );
    | |_________________^ help: try this: 'unwrap_or_else(|| panic!("[ERROR] condition in play \"{}\" not found in \"conditions.yaml\".", &condition.description))'
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call

I'd like to set a flag that makes these lint suggestions interactive. I'd like to be able to accept a code suggestion provided by clippy and have clippy update the code in my file. Would be curious to get other peoples' take on this idea.

@phansch
Copy link
Member

phansch commented Jul 25, 2019

This is going to be possible in one of the upcoming rust releases, it should be available on nightly once rust-lang/rust#62914 is merged and included in a nightly. The feature will initially be available via cargo fix --clippy.

There is some more work to be done on the Clippy side to make the suggestions more correct, though.

@flip1995
Copy link
Member

As @phansch mentioned, this feature was recently implemented in cargo. Here's the PR: rust-lang/cargo#7069

It will be available through cargo fix --clippy -Zunstable-options on nightly soon.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants