Skip to content

Commit 4adf294

Browse files
committed
Refactor lint categories into macro
1 parent eb04beb commit 4adf294

File tree

1 file changed

+33
-50
lines changed

1 file changed

+33
-50
lines changed

clippy_lints/src/lib.rs

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ use rustc_data_structures::fx::FxHashSet;
4747
use rustc_lint::LintId;
4848
use rustc_session::Session;
4949

50+
macro_rules! clippy_lint_categories {
51+
($macro:path, $($tail:tt)*) => {
52+
$macro!({
53+
correctness: Deny,
54+
complexity: Warn,
55+
perf: Warn,
56+
style: Warn,
57+
pedantic: Allow,
58+
restriction: Allow,
59+
cargo: Allow,
60+
nursery: Allow,
61+
internal: Allow,
62+
internal_warn: Warn,
63+
} $($tail)*);
64+
};
65+
}
66+
5067
/// Macro used to declare a Clippy lint.
5168
///
5269
/// Every lint declaration consists of 4 parts:
@@ -92,60 +109,26 @@ use rustc_session::Session;
92109
/// }
93110
/// ```
94111
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
95-
#[macro_export]
96-
macro_rules! declare_clippy_lint {
97-
{ $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
98-
declare_tool_lint! {
99-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
100-
}
101-
};
102-
{ $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
103-
declare_tool_lint! {
104-
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
105-
}
106-
};
107-
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
108-
declare_tool_lint! {
109-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
110-
}
111-
};
112-
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
113-
declare_tool_lint! {
114-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
115-
}
116-
};
117-
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
118-
declare_tool_lint! {
119-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
120-
}
121-
};
122-
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
123-
declare_tool_lint! {
124-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
125-
}
126-
};
127-
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
128-
declare_tool_lint! {
129-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
130-
}
131-
};
132-
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
133-
declare_tool_lint! {
134-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
135-
}
136-
};
137-
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
138-
declare_tool_lint! {
139-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
140-
}
141-
};
142-
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
143-
declare_tool_lint! {
144-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
112+
macro_rules! declare_clippy_lint_macro {
113+
({ $($category:tt: $level:tt,)* } $d:tt) => {
114+
macro_rules! declare_clippy_lint {
115+
$(
116+
($d(#[$d meta:meta])* pub $d name:tt, $category, $d description:tt) => {
117+
declare_tool_lint! {
118+
$d(#[$d meta])*
119+
pub clippy::$d name,
120+
$level,
121+
$d description,
122+
report_in_external_macro: true
123+
}
124+
};
125+
)*
145126
}
146127
};
147128
}
148129

130+
clippy_lint_categories!(declare_clippy_lint_macro, $);
131+
149132
#[macro_export]
150133
macro_rules! sym {
151134
( $($x:tt)* ) => { clippy_utils::sym!($($x)*) }

0 commit comments

Comments
 (0)