Skip to content

Commit 23ed792

Browse files
committed
Document new clippy::version attribute and make it mandatory
1 parent 8565fc4 commit 23ed792

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ opener = "0.5"
1212
regex = "1.5"
1313
shell-escape = "0.1"
1414
walkdir = "2.3"
15+
cargo_metadata = "0.12"
1516

1617
[features]
1718
deny-warnings = []

clippy_dev/src/new_lint.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ fn to_camel_case(name: &str) -> String {
132132
.collect()
133133
}
134134

135+
fn get_stabilisation_version() -> String {
136+
let mut command = cargo_metadata::MetadataCommand::new();
137+
command.no_deps();
138+
if let Ok(metadata) = command.exec() {
139+
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
140+
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
141+
}
142+
}
143+
144+
String::from("<TODO set version(see doc/adding_lints.md)")
145+
}
146+
135147
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
136148
let mut contents = format!(
137149
indoc! {"
@@ -178,6 +190,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
178190
},
179191
};
180192

193+
let version = get_stabilisation_version();
181194
let lint_name = lint.name;
182195
let category = lint.category;
183196
let name_camel = to_camel_case(lint.name);
@@ -212,7 +225,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
212225
});
213226

214227
result.push_str(&format!(
215-
indoc! {"
228+
indoc! {r#"
216229
declare_clippy_lint! {{
217230
/// ### What it does
218231
///
@@ -226,11 +239,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
226239
/// ```rust
227240
/// // example code which does not raise clippy warning
228241
/// ```
242+
#[clippy::version = "{version}"]
229243
pub {name_upper},
230244
{category},
231-
\"default lint description\"
245+
"default lint description"
232246
}}
233-
"},
247+
"#},
248+
version = version,
234249
name_upper = name_upper,
235250
category = category,
236251
));

clippy_dev/src/update_lints.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
1818
r#"(?x)
1919
declare_clippy_lint!\s*[\{(]
2020
(?:\s+///.*)*
21-
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
21+
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])
2222
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
2323
(?P<cat>[a-z_]+)\s*,\s*
2424
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
@@ -496,20 +496,23 @@ fn test_parse_contents() {
496496
let result: Vec<Lint> = parse_contents(
497497
r#"
498498
declare_clippy_lint! {
499+
#[clippy::version = "Hello Clippy!"]
499500
pub PTR_ARG,
500501
style,
501502
"really long \
502503
text"
503504
}
504505
505506
declare_clippy_lint!{
507+
#[clippy::version = "Test version"]
506508
pub DOC_MARKDOWN,
507509
pedantic,
508510
"single line"
509511
}
510512
511513
/// some doc comment
512514
declare_deprecated_lint! {
515+
#[clippy::version = "I'm a version"]
513516
pub SHOULD_ASSERT_EQ,
514517
"`assert!()` will be more flexible with RFC 2011"
515518
}

doc/adding_lints.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ declare_clippy_lint! {
189189
/// ```rust
190190
/// // example code
191191
/// ```
192+
#[clippy::version = "1.29.0"]
192193
pub FOO_FUNCTIONS,
193194
pedantic,
194195
"function named `foo`, which is not a descriptive name"
@@ -199,6 +200,10 @@ declare_clippy_lint! {
199200
section. This is the default documentation style and will be displayed
200201
[like this][example_lint_page]. To render and open this documentation locally
201202
in a browser, run `cargo dev serve`.
203+
* The `#[clippy::version]` attribute will be rendered as part of the lint documentation.
204+
The value should be set to the current Rust version that the lint is developed in,
205+
it can be retrieved by running `rustc -vV` in the rust-clippy directory. The version
206+
is listed under *release*. (Use the version without the `-nightly`) suffix.
202207
* `FOO_FUNCTIONS` is the name of our lint. Be sure to follow the
203208
[lint naming guidelines][lint_naming] here when naming your lint.
204209
In short, the name should state the thing that is being checked for and
@@ -503,6 +508,7 @@ declare_clippy_lint! {
503508
/// // Good
504509
/// Insert a short example of improved code that doesn't trigger the lint
505510
/// ```
511+
#[clippy::version = "1.29.0"]
506512
pub FOO_FUNCTIONS,
507513
pedantic,
508514
"function named `foo`, which is not a descriptive name"

0 commit comments

Comments
 (0)