# Should rust-analyzer run clippy by default?

**URL:** <https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766>\
**Category:** tools and infrastructure\
**Created:** [July 21, 2020, 1:20pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766 "2020-07-21T13:20:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [July 21, 2020, 1:20pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/1 "2020-07-21T13:20:41Z")

</div>

To get compiler errors, rust-analyzer runs `cargo check`. We _could_ run `cargo clippy` instead, the question is, should we?

At the moment we don't do that, but I the primary reason for that is historical (I just don't use clippy myself).

I am not sure how do decide here, so I figured that I'd just through the question here to get more feedback 🙂

To clarify, switching from `check` to clippy is simple, one needs to set `"rust-analyzer.checkOnSave.command": "clippy"` in the config file of the editor, this is specifically a question of defaults.

---

<div class="post-metadata">

**Author:** ![mjbshaw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mjbshaw/32/5103_2.png) [@mjbshaw](https://internals.rust-lang.org/u/mjbshaw)\
**Post date:** [July 21, 2020, 1:31pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/2 "2020-07-21T13:31:21Z")

</div>

I personally don't think clippy should be run by default. It should be easy to enable (and already is), but not the default. Running clippy by default is tantamount to just merging clippy intro rustc/rust-analyzer, IMO.

There's a reason clippy is separate from the core tooling. I don't think clippy should be run by default for this same reason.

---

<div class="post-metadata">

**Author:** ![rkuhn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/rkuhn/32/6659_2.png) [@rkuhn](https://internals.rust-lang.org/u/rkuhn)\
**Post date:** [July 21, 2020, 2:06pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/3 "2020-07-21T14:06:41Z")

</div>

I don’t have a strong opinion, in particular since it is reasonably easy to opt in, so just a thought: clippy also performs an analysis, so based on naming it _could_ be included by default.

---

<div class="post-metadata">

**Author:** ![OZ\_](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oz_/32/4298_2.png) [@OZ\_](https://internals.rust-lang.org/u/OZ_)\
**Post date:** [July 21, 2020, 2:09pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/4 "2020-07-21T14:09:27Z")

</div>

Of course not. Clippy is very opinionated - when I use it, I write multiple lines just to turn off the lints I don't like. If you will use Clippy without any configs - it will be very annoying.

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [July 21, 2020, 3:40pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/5 "2020-07-21T15:40:24Z")

</div>

As a counterpoint, whenever I use clippy (which is to say on all of my non trivial repos) I have multiple lines to turn _on_ lints that I think it should have enabled by default, and _never_ turn lints off project wide.

---

<div class="post-metadata">

**Author:** ![eminence](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/eminence/32/4018_2.png) [@eminence](https://internals.rust-lang.org/u/eminence)\
**Post date:** [July 21, 2020, 3:45pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/6 "2020-07-21T15:45:29Z")

</div>

This may be too subtle, but could rust-analyzer use the presence of a `clippy.toml` config file to figure out if it should run clippy by default? I know that this file is optional, and many people use clippy using the default settings (thus they do not have a clippy.toml). But the presence of this file might be a strong indicator that the developer is prepared to handle warnings issued by clippy and may want to see them in their IDE.

---

<div class="post-metadata">

**Author:** ![kinnison](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kinnison/32/5768_2.png) [@kinnison](https://internals.rust-lang.org/u/kinnison)\
**Post date:** [July 21, 2020, 3:47pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/7 "2020-07-21T15:47:57Z")

</div>

I really liked the `rls` approach here. If there were `#![warn(clippy::all)]` or similar in the crate it enables clippy, otherwise it just checks.

---

<div class="post-metadata">

**Author:** ![jonasbb](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jonasbb/32/2084_2.png) [@jonasbb](https://internals.rust-lang.org/u/jonasbb)\
**Post date:** [July 21, 2020, 4:21pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/8 "2020-07-21T16:21:08Z")

</div>

Personally I would prefer if it uses clippy by default since most/all default lints lead to better code in my experience. Detecting the use of clippy annotations and only using clippy if it detects a tool annotation or the configuration file also seems reasonable.

I think there are two further options not mentioned so far:

1. The IDE extension/rust-analyzer could ask the user once if they prefer to enable extended linting/clippy. Such a prompt also occurs for other extensions, for example the python Vscode extension asks for a choice between jedi, Microsoft languagesserver and pylance.
2. If the full set of clippy lints is too noisy, how about running only a subset of them by default? The obvious candidate here are the correctness lints which are deny by default.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [July 21, 2020, 5:52pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/9 "2020-07-21T17:52:26Z")

</div>

I think I roughly agree that the best possible behavior would be for the extension to prompt on first startup to chose the global setting between

- just r-a, no use of `cargo`
- always `cargo check`
- always `cargo clippy`
- if clippy.toml is present { `cargo clippy` } else { `cargo check` }

(And as a default before the user makes a choice, either just don't use cargo, or sniff clippy.toml.)

---

<div class="post-metadata">

**Author:** ![bheisler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bheisler/32/3189_2.png) [@bheisler](https://internals.rust-lang.org/u/bheisler)\
**Post date:** [July 21, 2020, 7:14pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/10 "2020-07-21T19:14:00Z")

</div>

I didn't know that there was an option to use clippy. Enabling that option is easy enough once someone knows it exists. Perhaps a happy medium would be to leave the defaults as they are and make the option more visible/discoverable to the user?

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [July 21, 2020, 7:41pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/11 "2020-07-21T19:41:08Z")

</div>

I think it should be incredibly easy ("check a box" easy) to turn on, but it should be off by default. Clippy is where lints go that aren't suitable to go in rustc directly (or aren't yet, but may be in the future). Enabling clippy by default would give a different impression of the language, and not necessarily the impression we want to give.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [July 21, 2020, 11:58pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/12 "2020-07-21T23:58:59Z")

</div>

Maybe run clippy if there are no other warnings in the project? I'm worried about hundreds of style lints like "you should format your numbers with thousands separators" drowning out real warnings.

---

<div class="post-metadata">

**Author:** ![djc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/djc/32/1592_2.png) [@djc](https://internals.rust-lang.org/u/djc)\
**Post date:** [July 22, 2020, 8:10am UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/13 "2020-07-22T08:10:42Z")

</div>

I'm with @josh here. I just went looking for the option to turn it on and couldn't find it in the Extensions settings in VS Code. It should definitely be there -- but not enabled by default.

Also I've seen quite a few issues where cargo clippy on the command-line (usually at the workspace level) doesn't show me warnings but then `cargo clippy --workspace --all-targets -- -D warnings` (which is what I use in CI) fails anyway. In other words, I'd hope the RA integration would set `--workspace --all-targets` by default or allow me to change the defaults.

---

<div class="post-metadata">

**Author:** ![dan\_t](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan\_t](https://internals.rust-lang.org/u/dan_t)\
**Post date:** [July 22, 2020, 8:42am UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/14 "2020-07-22T08:42:52Z")

</div>

If the warnings of clippy would be uncontroversial, then they would be in rustc.

Therefore I don't see a reason why the default experience with rustc and rust-analyzer should be any different.

---

<div class="post-metadata">

**Author:** ![gbutler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gbutler/32/3670_2.png) [@gbutler](https://internals.rust-lang.org/u/gbutler)\
**Post date:** [July 22, 2020, 4:37pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/15 "2020-07-22T16:37:59Z")

</div>

> [@mjbshaw](#):
>
> unning clippy by default is tantamount to just merging clippy intro rustc/rust-analyzer, IMO.

I don't see how that is so. This is talking about what the default should be for Rust IDE's that are using Rust Analyzer. Should they default to using "Clippy Lints"? Prior Art would suggest YES. Java and C#, for example, both enable the equivalent by default in all the normal IDE's for these languages.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [July 22, 2020, 4:58pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/16 "2020-07-22T16:58:13Z")

</div>

There's also another factor involved in IDE errors that changes the trade-off some: lints in the IDE aren't (typically) just presented in a big list. It's a lot easier to cut to "important" lints when they're specially spread out, as opposed to the output on the command line.

"Ideal" integrated behavior would be for all of the warnings (even the off-by-default ones!) to be reported to the IDE, which then you use the IDE's configuration to handle warning severity. (Complicating the matter is that clippy's warning model probably doesn't line up 1-1 with your IDEs warning model.)

---

<div class="post-metadata">

**Author:** ![felix.s](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/felix.s/32/8073_2.png) [@felix.s](https://internals.rust-lang.org/u/felix.s)\
**Post date:** [July 22, 2020, 9:32pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/17 "2020-07-22T21:32:19Z")

</div>

What if clippy is not installed?

I don't use clippy simply because I cannot install from normal Debian repositories, unlike the rest of Rust.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [July 22, 2020, 10:58pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/18 "2020-07-22T22:58:02Z")

</div>

Then, to be fair, you probably aren't using r-a either, because it's also not available in Debian upstream either.

I'm pretty sure that r-a assumes by default what you're using rustup and any other setup is still mostly on your own.

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)\
**Post date:** [July 22, 2020, 11:01pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/19 "2020-07-22T23:01:35Z")

</div>

Well, the downloaded `rust-analyzer` does work fine with my system toolchain on Fedora. AFAICS the only place it tries to actually invoke `rustup` is if `rust-src` is not found in the sysroot.

---

<div class="post-metadata">

**Author:** ![pickfire](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pickfire/32/3830_2.png) [@pickfire](https://internals.rust-lang.org/u/pickfire)\
**Post date:** [July 24, 2020, 2:04pm UTC](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766/20 "2020-07-24T14:04:58Z")

</div>

I don't even know how to configure rust-analyzer, I wish it is the default.

[Next page](https://internals.rust-lang.org/t/should-rust-analyzer-run-clippy-by-default/12766.md?page=2)
