We're trying to enable clippy::pedantic on neqo (https://github.com/mozilla/neqo/pull/187 for example) and, given there's lot of refactoring to be made all across the codebase, I was wondering if there was a way to filter clippy warnings only on the "current diff", erroring out or linting only the parts of the code that have been edited when working on an issue.
I was thinking of something like the clang format diff tool
I have no idea how hard it would be to implement, but I would love to implement it if someone would like to mentor me on that one.
Thank's a lot for your time.
There's currently no such script that does that. Such a script should apply on Rust warnings/errors in general though, not just on Clippy.
This could be done by getting the changed files from git and then filtering the JSON-output of the rust error messages by the file names. (cargo clippy --message-format json)
Fun-fact: this request is kind of the opposite of another long standing issue: #2604
Such a script should be implemented in Rust and not in Python, like the clang script, obviously. 馃槈
Some months ago I started a private project that does this in the form of a GitHub bot. I'll try and see if I can find some time to bring that to a MVP state and possibly open-source parts of it.
I have just checked the --message-format json output and it gives the line numbers, which I can then compare with a git diff, so it seems like a pet peeve I can work on, thanks for the hints!
@o0Ignition0o I just realized that my project was already open-source. You might want to have a look at
Feel free to copy things as you need :)
Wow thanks a lot, I hope I can come up with something useful this week !
Just published a very rough first draft of cargo-scout, that will run clippy in pedantic mode and only warn you on the lints that were raised in _your_ patch.
The code is ugly for now, and there's still a lot of bugs, which I want to fix as soon as I figure them out :)
https://github.com/o0Ignition0o/cargo-scout
There's still quite a lot to be improved, running cargo clean is often required before a clippy run, and I've probably allocated too much, oh and there aren't any tests... But I'll hopefully get there soon !
@phansch I've used the structures you deserialize into, do you mind me adding a "Inspiration" section at the bottom of the README.md with a special thanks to you ?
Sounds like an idea for great overall tool for Rust projects when it gains option to config which lints are enabled.
Another interesting idea is to include https://github.com/rust-lang/rustfmt/issues/1324. Large projects like Rust could really use some formatting but enabling it everywhere is not an option.
@phansch I've used the structures you deserialize into, do you mind me adding a "Inspiration" section at the bottom of the README.md with a special thanks to you ?
Not at all, I'm glad the code found some actual use =)
So as a little heads up, cargo-scout 0.3.0 is now out, and has all the features I wanted as I've opened this issue:
It only warns on the lints that intersect with your diff.
It iterates over workspace members if --no-default-features is passed for example.
It even handles the neqo use case where #[deny(warnings)] is behind a feature flag, which is part of the default feature set.
cargo-scout -p --no-default-features works well everywhere (-p makes it use clippy-preview with unstable features), except when there's a build-rs file, which is the case in neqo-crypto.
I'll dig further on that, but I'm pretty satisfied with the results so far !
Thank you all for helping me kickstart the project, which has now 5 other contributors doing some amazing things <3
Thanks for sharing! I suggested it as Crate of the Week in TWIR: https://users.rust-lang.org/t/crate-of-the-week/2704/694
Cargo-scout is crate of the week in this week in rust ! I鈥檓 really happy, and I鈥檝e already received some feedback (some suggesting the ability to use cargo fix, which was already brought up here). I鈥檓 gonna dig this way :)
Thanks a lot for the support !
Congratulations!
Most helpful comment
So as a little heads up, cargo-scout 0.3.0 is now out, and has all the features I wanted as I've opened this issue:
It only warns on the lints that intersect with your diff.
It iterates over workspace members if --no-default-features is passed for example.
It even handles the neqo use case where #[deny(warnings)] is behind a feature flag, which is part of the default feature set.
cargo-scout -p --no-default-featuresworks well everywhere (-p makes it use clippy-preview with unstable features), except when there's a build-rs file, which is the case in neqo-crypto.I'll dig further on that, but I'm pretty satisfied with the results so far !
Thank you all for helping me kickstart the project, which has now 5 other contributors doing some amazing things <3