New internal lint to make clippy::version attribute mandatory

This commit is contained in:
xFrednet 2021-11-11 12:54:53 +01:00
parent 94bc0a1c78
commit 8c45fd88d0
No known key found for this signature in database
GPG Key ID: FCDCBF29AF64D601
29 changed files with 130 additions and 32 deletions

View File

@ -13,6 +13,7 @@ store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
LintId::of(utils::internal_lints::INVALID_PATHS),
LintId::of(utils::internal_lints::LINT_WITHOUT_LINT_PASS),
LintId::of(utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM),
LintId::of(utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE),
LintId::of(utils::internal_lints::OUTER_EXPN_EXPN_DATA),
LintId::of(utils::internal_lints::PRODUCE_ICE),
LintId::of(utils::internal_lints::UNNECESSARY_SYMBOL_STR),

View File

@ -24,6 +24,8 @@ store.register_lints(&[
#[cfg(feature = "internal-lints")]
utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
#[cfg(feature = "internal-lints")]
utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE,
#[cfg(feature = "internal-lints")]
utils::internal_lints::OUTER_EXPN_EXPN_DATA,
#[cfg(feature = "internal-lints")]
utils::internal_lints::PRODUCE_ICE,

View File

@ -153,6 +153,10 @@ macro_rules! declare_clippy_lint {
#[cfg(feature = "metadata-collector-lint")]
mod deprecated_lints;
#[cfg_attr(
any(feature = "internal-lints", feature = "metadata-collector-lint"),
allow(clippy::missing_clippy_version_attribute)
)]
mod utils;
// begin lints modules, do not remove this comment, its used in `update_lints`

View File

@ -328,6 +328,15 @@ declare_clippy_lint! {
"found an invalid `clippy::version` attribute"
}
declare_clippy_lint! {
/// ### What it does
/// Checks for declared clippy lints without the `clippy::version` attribute.
///
pub MISSING_CLIPPY_VERSION_ATTRIBUTE,
internal,
"found clippy lint without `clippy::version` attribute"
}
declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
impl EarlyLintPass for ClippyLintsInternal {
@ -365,7 +374,7 @@ pub struct LintWithoutLintPass {
registered_lints: FxHashSet<Symbol>,
}
impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS, INVALID_CLIPPY_VERSION_ATTRIBUTE]);
impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS, INVALID_CLIPPY_VERSION_ATTRIBUTE, MISSING_CLIPPY_VERSION_ATTRIBUTE]);
impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
@ -492,6 +501,15 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'
"please use a valid sematic version, see `doc/adding_lints.md`",
);
}
} else {
span_lint_and_help(
cx,
MISSING_CLIPPY_VERSION_ATTRIBUTE,
item.span,
"this lint is missing the `clippy::version` attribute or version value",
None,
"please use a `clippy::version` attribute, see `doc/adding_lints.md`",
);
}
}

View File

@ -54,16 +54,34 @@ declare_tool_lint! {
}
///////////////////////
// Ignored attributes
// Missing attribute test
///////////////////////
declare_tool_lint! {
#[clippy::version]
pub clippy::IGNORED_ONE,
pub clippy::MISSING_ATTRIBUTE_ONE,
Warn,
"ONE",
"Two",
report_in_external_macro: true
}
declare_lint_pass!(Pass2 => [VALID_ONE, VALID_TWO, VALID_THREE, INVALID_ONE, INVALID_TWO, IGNORED_ONE]);
declare_tool_lint! {
pub clippy::MISSING_ATTRIBUTE_TWO,
Warn,
"Two",
report_in_external_macro: true
}
#[allow(clippy::missing_clippy_version_attribute)]
mod internal_clippy_lints {
declare_tool_lint! {
pub clippy::ALLOW_MISSING_ATTRIBUTE_ONE,
Warn,
"Two",
report_in_external_macro: true
}
}
use crate::internal_clippy_lints::ALLOW_MISSING_ATTRIBUTE_ONE;
declare_lint_pass!(Pass2 => [VALID_ONE, VALID_TWO, VALID_THREE, INVALID_ONE, INVALID_TWO, MISSING_ATTRIBUTE_ONE, MISSING_ATTRIBUTE_TWO, ALLOW_MISSING_ATTRIBUTE_ONE]);
fn main() {}

View File

@ -34,5 +34,40 @@ LL | | }
= help: please use a valid sematic version, see `doc/adding_lints.md`
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
error: this lint is missing the `clippy::version` attribute or version value
--> $DIR/check_clippy_version_attribute.rs:59:1
|
LL | / declare_tool_lint! {
LL | | #[clippy::version]
LL | | pub clippy::MISSING_ATTRIBUTE_ONE,
LL | | Warn,
LL | | "Two",
LL | | report_in_external_macro: true
LL | | }
| |_^
|
note: the lint level is defined here
--> $DIR/check_clippy_version_attribute.rs:1:9
|
LL | #![deny(clippy::internal)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::missing_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this lint is missing the `clippy::version` attribute or version value
--> $DIR/check_clippy_version_attribute.rs:67:1
|
LL | / declare_tool_lint! {
LL | | pub clippy::MISSING_ATTRIBUTE_TWO,
LL | | Warn,
LL | | "Two",
LL | | report_in_external_macro: true
LL | | }
| |_^
|
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors

View File

@ -1,5 +1,6 @@
// run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate clippy_utils;

View File

@ -1,5 +1,6 @@
// run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate clippy_utils;

View File

@ -1,5 +1,5 @@
error: this call is collapsible
--> $DIR/collapsible_span_lint_calls.rs:35:9
--> $DIR/collapsible_span_lint_calls.rs:36:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | | db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
@ -14,7 +14,7 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::collapsible_span_lint_calls)]` implied by `#[deny(clippy::internal)]`
error: this call is collapsible
--> $DIR/collapsible_span_lint_calls.rs:38:9
--> $DIR/collapsible_span_lint_calls.rs:39:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | | db.span_help(expr.span, help_msg);
@ -22,7 +22,7 @@ LL | | });
| |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg)`
error: this call is collapsible
--> $DIR/collapsible_span_lint_calls.rs:41:9
--> $DIR/collapsible_span_lint_calls.rs:42:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | | db.help(help_msg);
@ -30,7 +30,7 @@ LL | | });
| |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg)`
error: this call is collspible
--> $DIR/collapsible_span_lint_calls.rs:44:9
--> $DIR/collapsible_span_lint_calls.rs:45:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | | db.span_note(expr.span, note_msg);
@ -38,7 +38,7 @@ LL | | });
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)`
error: this call is collspible
--> $DIR/collapsible_span_lint_calls.rs:47:9
--> $DIR/collapsible_span_lint_calls.rs:48:9
|
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
LL | | db.note(note_msg);

View File

@ -4,6 +4,7 @@
// normalize-stderr-test: "', .*clippy_lints" -> "', clippy_lints"
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
fn it_looks_like_you_are_trying_to_kill_clippy() {}

View File

@ -1,4 +1,5 @@
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
#[macro_use]

View File

@ -1,5 +1,5 @@
error: the lint `TEST_LINT_DEFAULT` has the default lint description
--> $DIR/default_lint.rs:17:1
--> $DIR/default_lint.rs:18:1
|
LL | / declare_tool_lint! {
LL | | pub clippy::TEST_LINT_DEFAULT,

View File

@ -1,5 +1,5 @@
#![warn(clippy::if_chain_style)]
#![allow(clippy::no_effect, clippy::nonminimal_bool)]
#![allow(clippy::no_effect, clippy::nonminimal_bool, clippy::missing_clippy_version_attribute)]
extern crate if_chain;

View File

@ -1,5 +1,6 @@
// run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate rustc_span;

View File

@ -1,5 +1,6 @@
// run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate rustc_span;

View File

@ -1,5 +1,5 @@
error: interning a defined symbol
--> $DIR/interning_defined_symbol.rs:17:13
--> $DIR/interning_defined_symbol.rs:18:13
|
LL | let _ = Symbol::intern("f32");
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::f32`
@ -12,19 +12,19 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::interning_defined_symbol)]` implied by `#[deny(clippy::internal)]`
error: interning a defined symbol
--> $DIR/interning_defined_symbol.rs:20:13
--> $DIR/interning_defined_symbol.rs:21:13
|
LL | let _ = sym!(f32);
| ^^^^^^^^^ help: try: `rustc_span::sym::f32`
error: interning a defined symbol
--> $DIR/interning_defined_symbol.rs:23:13
--> $DIR/interning_defined_symbol.rs:24:13
|
LL | let _ = Symbol::intern("proc-macro");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::proc_dash_macro`
error: interning a defined symbol
--> $DIR/interning_defined_symbol.rs:26:13
--> $DIR/interning_defined_symbol.rs:27:13
|
LL | let _ = Symbol::intern("self");
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::symbol::kw::SelfLower`

View File

@ -1,4 +1,5 @@
#![warn(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
mod paths {
// Good path

View File

@ -1,5 +1,5 @@
error: invalid path
--> $DIR/invalid_paths.rs:17:5
--> $DIR/invalid_paths.rs:18:5
|
LL | pub const BAD_CRATE_PATH: [&str; 2] = ["bad", "path"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | pub const BAD_CRATE_PATH: [&str; 2] = ["bad", "path"];
= note: `-D clippy::invalid-paths` implied by `-D warnings`
error: invalid path
--> $DIR/invalid_paths.rs:20:5
--> $DIR/invalid_paths.rs:21:5
|
LL | pub const BAD_MOD_PATH: [&str; 2] = ["std", "xxx"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,4 +1,5 @@
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
#[macro_use]

View File

@ -1,5 +1,5 @@
error: the lint `TEST_LINT` is not added to any `LintPass`
--> $DIR/lint_without_lint_pass.rs:11:1
--> $DIR/lint_without_lint_pass.rs:12:1
|
LL | / declare_tool_lint! {
LL | | pub clippy::TEST_LINT,

View File

@ -1,4 +1,5 @@
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate clippy_utils;

View File

@ -1,5 +1,5 @@
error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item
--> $DIR/match_type_on_diag_item.rs:30:17
--> $DIR/match_type_on_diag_item.rs:31:17
|
LL | let _ = match_type(cx, ty, &OPTION);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Option)`
@ -12,13 +12,13 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::match_type_on_diagnostic_item)]` implied by `#[deny(clippy::internal)]`
error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item
--> $DIR/match_type_on_diag_item.rs:31:17
--> $DIR/match_type_on_diag_item.rs:32:17
|
LL | let _ = match_type(cx, ty, &["core", "result", "Result"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Result)`
error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item
--> $DIR/match_type_on_diag_item.rs:34:17
--> $DIR/match_type_on_diag_item.rs:35:17
|
LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Rc)`

View File

@ -1,6 +1,7 @@
// run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate rustc_hir;

View File

@ -1,6 +1,7 @@
// run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
extern crate rustc_hir;

View File

@ -1,5 +1,5 @@
error: usage of `outer_expn().expn_data()`
--> $DIR/outer_expn_data.rs:24:34
--> $DIR/outer_expn_data.rs:25:34
|
LL | let _ = expr.span.ctxt().outer_expn().expn_data();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `outer_expn_data()`

View File

@ -1,7 +1,11 @@
// run-rustfix
#![feature(rustc_private)]
#![deny(clippy::internal)]
#![allow(clippy::unnecessary_operation, unused_must_use)]
#![allow(
clippy::unnecessary_operation,
unused_must_use,
clippy::missing_clippy_version_attribute
)]
extern crate rustc_span;

View File

@ -1,7 +1,11 @@
// run-rustfix
#![feature(rustc_private)]
#![deny(clippy::internal)]
#![allow(clippy::unnecessary_operation, unused_must_use)]
#![allow(
clippy::unnecessary_operation,
unused_must_use,
clippy::missing_clippy_version_attribute
)]
extern crate rustc_span;

View File

@ -1,5 +1,5 @@
error: unnecessary `Symbol` to string conversion
--> $DIR/unnecessary_symbol_str.rs:11:5
--> $DIR/unnecessary_symbol_str.rs:15:5
|
LL | Symbol::intern("foo").as_str() == "clippy";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::sym::clippy`
@ -12,25 +12,25 @@ LL | #![deny(clippy::internal)]
= note: `#[deny(clippy::unnecessary_symbol_str)]` implied by `#[deny(clippy::internal)]`
error: unnecessary `Symbol` to string conversion
--> $DIR/unnecessary_symbol_str.rs:12:5
--> $DIR/unnecessary_symbol_str.rs:16:5
|
LL | Symbol::intern("foo").to_string() == "self";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower`
error: unnecessary `Symbol` to string conversion
--> $DIR/unnecessary_symbol_str.rs:13:5
--> $DIR/unnecessary_symbol_str.rs:17:5
|
LL | Symbol::intern("foo").to_ident_string() != "Self";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper`
error: unnecessary `Symbol` to string conversion
--> $DIR/unnecessary_symbol_str.rs:14:5
--> $DIR/unnecessary_symbol_str.rs:18:5
|
LL | &*Ident::empty().as_str() == "clippy";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy`
error: unnecessary `Symbol` to string conversion
--> $DIR/unnecessary_symbol_str.rs:15:5
--> $DIR/unnecessary_symbol_str.rs:19:5
|
LL | "clippy" == Ident::empty().to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name`

View File

@ -347,7 +347,8 @@ Otherwise, have a great day =^.^=
</div>
<!-- Clippy version -->
<div class="lint-additional-info-item">
Added in: <span class="label label-default label-version">{{lint.version}}</span>
<span>{{lint.group == "deprecated" ? "Deprecated" : "Added"}} in: </span>
<span class="label label-default label-version">{{lint.version}}</span>
</div>
<!-- Open related issues -->
<div class="lint-additional-info-item">