Checks for allow
attributes whose scope could be reduced.
An allow
attribute whose scope is too large could suppress warnings/errors and cause them
to go unnoticed.
- Recommends to reduce to the following scopes only (not arbitrary inner scopes):
- item
- trait item
impl
item- statement
- expression at the end of a block
- Cannot see inside
#[test]
functions, i.e., does not recommend to reduce to a scope smaller than an entire test. --force-warn
does not overrideclippy.toml
settings. So ifallow-unwrap-in-tests
is set totrue
,overscoped_allow
will not recommend to reduce scopes inside modules marked with#[cfg(test)]
, for example.
Two steps are required:
-
For the lint whose
allow
scopes you want to check, run it at theforce-warn
level and store the resulting warnings in a file calledwarnings.json
. For example, to check the scopes ofallow(clippy::unwrap_used)
, you might run the following command:cargo clippy --message-format=json -- --force-warn clippy::unwrap-used > warnings.json
To perform a similar check for the Dylint lint
non_thread_safe_call_in_test
, you might run the following command:DYLINT_RUSTFLAGS='--force-warn non_thread_safe_call_in_test' cargo dylint \ --lib non_thread_safe_call_in_test -- --message-format=json > warnings.json
-
Run the
overscoped_allow
lint. The lint will find and use thewarnings.json
file generated in 1.
To use a file other than warnings.json
, store that file's path in the environment variable
variable OVERSCOPED_ALLOW_PATH
.
#[allow(clippy::module_name_repetitions)]
mod cake {
struct BlackForestCake;
}
Use instead:
mod cake {
#[allow(clippy::module_name_repetitions)]
struct BlackForestCake;
}