Add disallowed_macros lint

This commit is contained in:
Alex Macleod 2022-10-05 13:44:01 +00:00
parent 425e1ea73d
commit 86c86c3742
23 changed files with 500 additions and 110 deletions

View file

@ -0,0 +1,36 @@
### What it does
Denies the configured macros in clippy.toml
Note: Even though this lint is warn-by-default, it will only trigger if
macros are defined in the clippy.toml file.
### Why is this bad?
Some macros are undesirable in certain contexts, and it's beneficial to
lint for them as needed.
### Example
An example clippy.toml configuration:
```
disallowed-macros = [
# Can use a string as the path of the disallowed macro.
"std::print",
# Can also use an inline table with a `path` key.
{ path = "std::println" },
# When using an inline table, can add a `reason` for why the macro
# is disallowed.
{ path = "serde::Serialize", reason = "no serializing" },
]
```
```
use serde::Serialize;
// Example code where clippy issues a warning
println!("warns");
// The diagnostic will contain the message "no serializing"
#[derive(Serialize)]
struct Data {
name: String,
value: usize,
}
```