Skip to content

Commit 9435077

Browse files
committed
New internal lint to make clippy::version attribute mandatory
1 parent 94bc0a1 commit 9435077

29 files changed

+129
-31
lines changed

clippy_lints/src/lib.register_internal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
1313
LintId::of(utils::internal_lints::INVALID_PATHS),
1414
LintId::of(utils::internal_lints::LINT_WITHOUT_LINT_PASS),
1515
LintId::of(utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM),
16+
LintId::of(utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE),
1617
LintId::of(utils::internal_lints::OUTER_EXPN_EXPN_DATA),
1718
LintId::of(utils::internal_lints::PRODUCE_ICE),
1819
LintId::of(utils::internal_lints::UNNECESSARY_SYMBOL_STR),

clippy_lints/src/lib.register_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ store.register_lints(&[
2424
#[cfg(feature = "internal-lints")]
2525
utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
2626
#[cfg(feature = "internal-lints")]
27+
utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE,
28+
#[cfg(feature = "internal-lints")]
2729
utils::internal_lints::OUTER_EXPN_EXPN_DATA,
2830
#[cfg(feature = "internal-lints")]
2931
utils::internal_lints::PRODUCE_ICE,

clippy_lints/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ macro_rules! declare_clippy_lint {
153153

154154
#[cfg(feature = "metadata-collector-lint")]
155155
mod deprecated_lints;
156+
#[cfg_attr(
157+
any(feature = "internal-lints", feature = "metadata-collector-lint"),
158+
allow(clippy::missing_clippy_version_attribute)
159+
)]
156160
mod utils;
157161

158162
// begin lints modules, do not remove this comment, it’s used in `update_lints`

clippy_lints/src/utils/internal_lints.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ declare_clippy_lint! {
328328
"found an invalid `clippy::version` attribute"
329329
}
330330

331+
declare_clippy_lint! {
332+
/// ### What it does
333+
/// Checks for declared clippy lints without the `clippy::version` attribute.
334+
///
335+
pub MISSING_CLIPPY_VERSION_ATTRIBUTE,
336+
internal,
337+
"found clippy lint without `clippy::version` attribute"
338+
}
339+
331340
declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
332341

333342
impl EarlyLintPass for ClippyLintsInternal {
@@ -492,6 +501,15 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'
492501
"please use a valid sematic version, see `doc/adding_lints.md`",
493502
);
494503
}
504+
} else {
505+
span_lint_and_help(
506+
cx,
507+
MISSING_CLIPPY_VERSION_ATTRIBUTE,
508+
item.span,
509+
"this lint is missing the `clippy::version` attribute or version value",
510+
None,
511+
"please use a `clippy::version` attribute, see `doc/adding_lints.md`",
512+
);
495513
}
496514
}
497515

tests/ui-internal/check_clippy_version_attribute.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,34 @@ declare_tool_lint! {
5454
}
5555

5656
///////////////////////
57-
// Ignored attributes
57+
// Missing attribute test
5858
///////////////////////
5959
declare_tool_lint! {
6060
#[clippy::version]
61-
pub clippy::IGNORED_ONE,
61+
pub clippy::MISSING_ATTRIBUTE_ONE,
6262
Warn,
63-
"ONE",
63+
"Two",
6464
report_in_external_macro: true
6565
}
6666

67-
declare_lint_pass!(Pass2 => [VALID_ONE, VALID_TWO, VALID_THREE, INVALID_ONE, INVALID_TWO, IGNORED_ONE]);
67+
declare_tool_lint! {
68+
pub clippy::MISSING_ATTRIBUTE_TWO,
69+
Warn,
70+
"Two",
71+
report_in_external_macro: true
72+
}
73+
74+
#[allow(clippy::missing_clippy_version_attribute)]
75+
mod internal_clippy_lints {
76+
declare_tool_lint! {
77+
pub clippy::ALLOW_MISSING_ATTRIBUTE_ONE,
78+
Warn,
79+
"Two",
80+
report_in_external_macro: true
81+
}
82+
}
83+
84+
use crate::internal_clippy_lints::ALLOW_MISSING_ATTRIBUTE_ONE;
85+
declare_lint_pass!(Pass2 => [VALID_ONE, VALID_TWO, VALID_THREE, INVALID_ONE, INVALID_TWO, MISSING_ATTRIBUTE_ONE, MISSING_ATTRIBUTE_TWO, ALLOW_MISSING_ATTRIBUTE_ONE]);
6886

6987
fn main() {}

tests/ui-internal/check_clippy_version_attribute.stderr

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,40 @@ LL | | }
3434
= help: please use a valid sematic version, see `doc/adding_lints.md`
3535
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

37-
error: aborting due to 2 previous errors
37+
error: this lint is missing the `clippy::version` attribute or version value
38+
--> $DIR/check_clippy_version_attribute.rs:59:1
39+
|
40+
LL | / declare_tool_lint! {
41+
LL | | #[clippy::version]
42+
LL | | pub clippy::MISSING_ATTRIBUTE_ONE,
43+
LL | | Warn,
44+
LL | | "Two",
45+
LL | | report_in_external_macro: true
46+
LL | | }
47+
| |_^
48+
|
49+
note: the lint level is defined here
50+
--> $DIR/check_clippy_version_attribute.rs:1:9
51+
|
52+
LL | #![deny(clippy::internal)]
53+
| ^^^^^^^^^^^^^^^^
54+
= note: `#[deny(clippy::missing_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
55+
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
56+
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
57+
58+
error: this lint is missing the `clippy::version` attribute or version value
59+
--> $DIR/check_clippy_version_attribute.rs:67:1
60+
|
61+
LL | / declare_tool_lint! {
62+
LL | | pub clippy::MISSING_ATTRIBUTE_TWO,
63+
LL | | Warn,
64+
LL | | "Two",
65+
LL | | report_in_external_macro: true
66+
LL | | }
67+
| |_^
68+
|
69+
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
70+
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
71+
72+
error: aborting due to 4 previous errors
3873

tests/ui-internal/collapsible_span_lint_calls.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
#![deny(clippy::internal)]
3+
#![allow(clippy::missing_clippy_version_attribute)]
34
#![feature(rustc_private)]
45

56
extern crate clippy_utils;

tests/ui-internal/collapsible_span_lint_calls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22
#![deny(clippy::internal)]
3+
#![allow(clippy::missing_clippy_version_attribute)]
34
#![feature(rustc_private)]
45

56
extern crate clippy_utils;

tests/ui-internal/collapsible_span_lint_calls.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this call is collapsible
2-
--> $DIR/collapsible_span_lint_calls.rs:35:9
2+
--> $DIR/collapsible_span_lint_calls.rs:36:9
33
|
44
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
55
LL | | db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable);
@@ -14,31 +14,31 @@ LL | #![deny(clippy::internal)]
1414
= note: `#[deny(clippy::collapsible_span_lint_calls)]` implied by `#[deny(clippy::internal)]`
1515

1616
error: this call is collapsible
17-
--> $DIR/collapsible_span_lint_calls.rs:38:9
17+
--> $DIR/collapsible_span_lint_calls.rs:39:9
1818
|
1919
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
2020
LL | | db.span_help(expr.span, help_msg);
2121
LL | | });
2222
| |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg)`
2323

2424
error: this call is collapsible
25-
--> $DIR/collapsible_span_lint_calls.rs:41:9
25+
--> $DIR/collapsible_span_lint_calls.rs:42:9
2626
|
2727
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
2828
LL | | db.help(help_msg);
2929
LL | | });
3030
| |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg)`
3131

3232
error: this call is collspible
33-
--> $DIR/collapsible_span_lint_calls.rs:44:9
33+
--> $DIR/collapsible_span_lint_calls.rs:45:9
3434
|
3535
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
3636
LL | | db.span_note(expr.span, note_msg);
3737
LL | | });
3838
| |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)`
3939

4040
error: this call is collspible
41-
--> $DIR/collapsible_span_lint_calls.rs:47:9
41+
--> $DIR/collapsible_span_lint_calls.rs:48:9
4242
|
4343
LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| {
4444
LL | | db.note(note_msg);

tests/ui-internal/custom_ice_message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// normalize-stderr-test: "', .*clippy_lints" -> "', clippy_lints"
55

66
#![deny(clippy::internal)]
7+
#![allow(clippy::missing_clippy_version_attribute)]
78

89
fn it_looks_like_you_are_trying_to_kill_clippy() {}
910

0 commit comments

Comments
 (0)