Skip to content

Commit a8cb916

Browse files
committed
docs(dev-guide/linting): improve wording
1 parent fae9a26 commit a8cb916

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

doc/dev-guide/src/linting.md

+38-13
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
11
# Linting
22

3-
We use `cargo clippy` to ensure high-quality code and to enforce a set of best practices for Rust programming. However, not all lints provided by `cargo clippy` are relevant or applicable to our project.
3+
We use `cargo clippy` to ensure high-quality code and to enforce a set of best practices for Rust programming.
4+
However, not all lints provided by `cargo clippy` are relevant or applicable to our project.
45
We may choose to ignore some lints if they are unstable, experimental, or specific to our project.
56
If you are unsure about a lint, please ask us in the [rustup Discord channel](https://discord.com/channels/442252698964721669/463480252723888159).
67

78
## Manual linting
89

9-
When checking the codebase with [`clippy`](https://doc.rust-lang.org/stable/clippy/index.html), it is recommended to use:
10+
When checking the codebase with [`clippy`](https://doc.rust-lang.org/stable/clippy/index.html),
11+
it is recommended to use the following command:
1012

1113
```console
1214
$ cargo clippy --all --all-targets --all-features -- -D warnings
1315
```
1416

17+
Please note the `--all-features` flag: it is used because we need to enable the `test` feature
18+
to make lints fully work, for which `--all-features` happens to be a convenient shortcut.
19+
20+
The `test` feature is required because `rustup` uses
21+
[cargo features](https://doc.rust-lang.org/cargo/reference/features.html) to
22+
[conditionally compile](https://doc.rust-lang.org/reference/conditional-compilation.html)
23+
support code for integration tests, as `#[cfg(test)]` is only available for unit tests.
24+
25+
If you encounter an issue or wish to speed up the initial analysis, you could also try
26+
activating only the `test` feature by replacing `--all-features` with `--features=test`.
27+
1528
## Rust-Analyzer
1629

17-
When using [`rust-analyzer`](https://rust-analyzer.github.io/) integration in the IDE of your choice, you might want to set the `rust-analyzer.cargo.features` configuration to `"all"` (check the [`rust-analyzer` manual](https://rust-analyzer.github.io/manual.html#configuration) for more details).
30+
When checking the codebase using `rust-analyzer`, the first thing to do remains unchanged:
31+
enabling the features.
1832

19-
### VSCode/VSCodium setup
33+
This is done by setting the `rust-analyzer.cargo.features` property to `"all"`.
2034

21-
Add
35+
For example, if you are using `rust-analyzer` within VSCode, you would want to
36+
add the following to your project's `.vscode/settings.json`[^vscode-global-cfg]:
2237

23-
```json
24-
"rust-analyzer.cargo.features": "all":,
38+
```jsonc
39+
"rust-analyzer.cargo.features": "all",
2540
```
2641

27-
in your project at `.vscode/settings.json`
42+
[^vscode-global-cfg]:
43+
Alternatively, if you want to apply the configuration to all your Rust projects,
44+
you can add it to your global configuration at `~/.config/Code/User/settings.json` instead.
2845

29-
or
30-
31-
to your global configuration `~/.config/Code/User/settings.json` (although you need to be aware that this will apply to all your Rust projects).
46+
Alternatively, if you want to enable the `test` feature only, you should set the
47+
following instead:
3248

49+
```jsonc
50+
"rust-analyzer.cargo.features": ["test"]
51+
```
3352

34-
## Rationale
53+
Next, as `rust-analyzer` depends on `cargo check` by default, it is also recommended to
54+
enable the `cargo clippy` integration by adding the following:
3555

36-
`rustup` uses cargo [features](https://doc.rust-lang.org/cargo/reference/features.html) in order to setup [conditional compilation](https://doc.rust-lang.org/reference/conditional-compilation.html) for integration tests as the `#[cfg(test)]` is only available for unit tests. To this end, the `test` feature has been created, however it then needs to be activated in order for tests and linting to fully work. As a shortcut we then propose to activate all features. However, if you encounter an issue, you could try activating only the `test` feature by setting the `rust-analyzer.cargo.features` configuration to `["test"]`.
56+
```jsonc
57+
"rust-analyzer.check.command": "clippy",
58+
```
3759

60+
You might also want to refer to the
61+
[`rust-analyzer` manual](https://rust-analyzer.github.io/manual.html#configuration)
62+
for more details on properly setting up `rust-analyzer` in your IDE of choice.

0 commit comments

Comments
 (0)