Fix allow_attributes_without_reason applying to external crate macros

Previously the `clippy::allow_attributes_without_reason` lint would
apply to external crate macros. Many macros in the Rust ecosystem
include these `allow` attributes without adding a reason, making this
lint pretty much unusable in any sizable Rust project.

This commit fixes that by adding a check to the lint if the attribute is
from an external crate macro and returning early.
This commit is contained in:
Cody 2022-10-10 23:37:09 -05:00
parent cf72565a12
commit 9ebd691612
No known key found for this signature in database
GPG Key ID: 1DE927325E9932E7

View File

@ -464,6 +464,11 @@ fn check_lint_reason(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem
return;
}
// Check if the attribute is in an external macro and therefore out of the developer's control
if in_external_macro(cx.sess(), attr.span) {
return;
}
span_lint_and_help(
cx,
ALLOW_ATTRIBUTES_WITHOUT_REASON,