rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.8k stars 1.53k forks source link

[Feature request] Custom linter #9340

Open haoadoreorange opened 3 years ago

haoadoreorange commented 3 years ago

Hi, Sorry if this is not the right place to ask. Currently I see no way to use another linter rather than clippy. Is there any hacky way to achieve this ?

flodiebold commented 3 years ago

You can set any Cargo command for checkOnSave.command, so as long as the other linter works as a subcommand like clippy (and supports JSON output), you can configure it the same way.

haoadoreorange commented 3 years ago

You can set any Cargo command for checkOnSave.command, so as long as the other linter works as a subcommand like clippy (and supports JSON output), you can configure it the same way.

Do you have any reference for the JSON output of clippy (what format should it be, specs, ...etc.) ? I looked around but couldn't find anything anywhere., so I'm a bit looking to a black box here.

lnicola commented 3 years ago

You can start from flycheck, it's the part of RA that runs cargo check. But I suspect that even running that yourself on a project with a couple of errors and warnings will be illuminating (clippy shares the same protocol as cargo check).

haoadoreorange commented 3 years ago

Thanks I will start with that. One more question regarding the option checkOnSave.command, is the description msg a bit confuse or I misunderstand. It says Cargo command to use for cargo check so it is as if cargo check will always be used (which doesn't make sense cuz there no subcommand anw). I ask because there is also an option overrideCommand.

lnicola commented 3 years ago

You can set the first one to clippy or the second one to cargo clippy --message-format=json. The first one is a convenience.

haoadoreorange commented 3 years ago

Ok so maybe the msg should change a bit for clarification ? What do you think ?

lnicola commented 3 years ago

"to use with cargo instead of check" would probably be more precise.