Skip to content

Commit 611b218

Browse files
xFrednetcamsteffen
andcommitted
Create macro to create Clippy's declare_clippy_lint macro
This is a revival of rust-lang#6830. It was closed to keep the currently simple implementation. However, with the upcoming changes it's better to follow the DRY princliple. Co-authored-by: camsteffen <[email protected]>
1 parent c37d6ee commit 611b218

File tree

1 file changed

+31
-55
lines changed

1 file changed

+31
-55
lines changed

clippy_lints/src/lib.rs

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -96,65 +96,41 @@ use rustc_session::Session;
9696
/// }
9797
/// ```
9898
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
99-
#[macro_export]
100-
macro_rules! declare_clippy_lint {
101-
{ $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
102-
declare_tool_lint! {
103-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
104-
}
105-
};
106-
{ $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
107-
declare_tool_lint! {
108-
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
109-
}
110-
};
111-
{ $(#[$attr:meta])* pub $name:tt, suspicious, $description:tt } => {
112-
declare_tool_lint! {
113-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
114-
}
115-
};
116-
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
117-
declare_tool_lint! {
118-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
119-
}
120-
};
121-
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
122-
declare_tool_lint! {
123-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
124-
}
125-
};
126-
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
127-
declare_tool_lint! {
128-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
129-
}
130-
};
131-
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
132-
declare_tool_lint! {
133-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
134-
}
135-
};
136-
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
137-
declare_tool_lint! {
138-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
139-
}
140-
};
141-
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
142-
declare_tool_lint! {
143-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
144-
}
145-
};
146-
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
147-
declare_tool_lint! {
148-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
149-
}
150-
};
151-
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
152-
declare_tool_lint! {
153-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
99+
macro_rules! declare_clippy_lint_macro {
100+
({ $($category:tt: $level:tt,)* }, $d:tt) => {
101+
macro_rules! declare_clippy_lint {
102+
$(
103+
($d(#[$d meta:meta])* pub $d name:tt, $category, $d description:tt) => {
104+
declare_tool_lint! {
105+
$d(#[$d meta])*
106+
pub clippy::$d name,
107+
$level,
108+
$d description,
109+
report_in_external_macro: true
110+
}
111+
};
112+
)*
154113
}
155114
};
156115
}
157116

117+
declare_clippy_lint_macro! {
118+
{
119+
correctness: Deny,
120+
complexity: Warn,
121+
perf: Warn,
122+
style: Warn,
123+
suspicious: Warn,
124+
pedantic: Allow,
125+
restriction: Allow,
126+
cargo: Allow,
127+
nursery: Allow,
128+
internal: Allow,
129+
internal_warn: Warn,
130+
},
131+
$
132+
}
133+
158134
#[cfg(feature = "internal")]
159135
mod deprecated_lints;
160136
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]

0 commit comments

Comments
 (0)