about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-26 15:53:46 +0000
committerbors <bors@rust-lang.org>2024-02-26 15:53:46 +0000
commita11875bd226a5ecedd87b766bfe4f7bd2df32299 (patch)
tree29e4235d0be6472520174ab118b3f7f30b0742c5
parentb09fb8ab3be9144725289ae89e60bb28301fe3c0 (diff)
parent6d0b70e08f4057ceb42ab997a199931fb80eb314 (diff)
downloadrust-a11875bd226a5ecedd87b766bfe4f7bd2df32299.tar.gz
rust-a11875bd226a5ecedd87b766bfe4f7bd2df32299.zip
Auto merge of #12353 - lucarlig:book, r=flip1995
add cargo.toml lint section way of adding lints in the book

changelog: add cargo.toml lint section way of adding lints in the book

as from [discussion on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20clippy.20config)
-rw-r--r--book/src/configuration.md41
1 files changed, 29 insertions, 12 deletions
diff --git a/book/src/configuration.md b/book/src/configuration.md
index 05520346456..9eb067abd91 100644
--- a/book/src/configuration.md
+++ b/book/src/configuration.md
@@ -33,26 +33,29 @@ disallowed-names = ["bar", ".."] # -> ["bar", "foo", "baz", "quux"]
 To deactivate the "for further information visit *lint-link*" message you can define the `CLIPPY_DISABLE_DOCS_LINKS`
 environment variable.
 
-### Allowing/denying lints
+### Allowing/Denying Lints
 
-You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
+#### Attributes in Code
 
-* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`)
+You can add attributes to your code to `allow`/`warn`/`deny` Clippy lints:
 
-* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
-  `#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive lints prone to false
-  positives.
+* the whole set of `warn`-by-default lints using the `clippy` lint group (`#![allow(clippy::all)]`)
+
+* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![warn(clippy::all, clippy::pedantic)]`. Note
+  that `clippy::pedantic` contains some very aggressive lints prone to false positives.
 
 * only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
 
 * `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc.
 
 Note: `allow` means to suppress the lint for your code. With `warn` the lint will only emit a warning, while with `deny`
-the lint will emit an error, when triggering for your code. An error causes clippy to exit with an error code, so is
-useful in scripts like CI/CD.
+the lint will emit an error, when triggering for your code. An error causes Clippy to exit with an error code, so is
+most useful in scripts used in CI/CD.
+
+#### Command Line Flags
 
-If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra
-flags to Clippy during the run:
+If you do not want to include your lint levels in the code, you can globally enable/disable lints by passing extra flags
+to Clippy during the run:
 
 To allow `lint_name`, run
 
@@ -66,19 +69,33 @@ And to warn on `lint_name`, run
 cargo clippy -- -W clippy::lint_name
 ```
 
-This also works with lint groups. For example, you can run Clippy with warnings for all lints enabled:
+This also works with lint groups. For example, you can run Clippy with warnings for all pedantic lints enabled:
 
 ```terminal
 cargo clippy -- -W clippy::pedantic
 ```
 
-If you care only about a single lint, you can allow all others and then explicitly warn on the lint(s) you are
+If you care only about a certain lints, you can allow all others and then explicitly warn on the lints you are
 interested in:
 
 ```terminal
 cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
 ```
 
+#### Lints Section in `Cargo.toml`
+
+Finally, lints can be allowed/denied using [the lints
+section](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section)) in the `Cargo.toml` file:
+
+To deny `clippy::enum_glob_use`, put the following in the `Cargo.toml`:
+
+```toml
+[lints.clippy]
+enum_glob_use = "deny"
+```
+
+For more details and options, refer to the Cargo documentation.
+
 ### Specifying the minimum supported Rust version
 
 Projects that intend to support old versions of Rust can disable lints pertaining to newer features by specifying the