Skip to content

Commit 56d7245

Browse files
committed
Document new clippy::version attribute and make it mandatory
1 parent 471dc4a commit 56d7245

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
@@ -104,6 +104,18 @@ fn to_camel_case(name: &str) -> String {
104104
.collect()
105105
}
106106

107+
fn get_stabilisation_version() -> String {
108+
let mut command = cargo_metadata::MetadataCommand::new();
109+
command.no_deps();
110+
if let Ok(metadata) = command.exec() {
111+
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
112+
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
113+
}
114+
}
115+
116+
String::from("<TODO set version(see doc/adding_lints.md)")
117+
}
118+
107119
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
108120
let mut contents = format!(
109121
indoc! {"
@@ -150,6 +162,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
150162
},
151163
};
152164

165+
let version = get_stabilisation_version();
153166
let lint_name = lint.name;
154167
let pass_name = lint.pass;
155168
let category = lint.category;
@@ -185,7 +198,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
185198
});
186199

187200
result.push_str(&format!(
188-
indoc! {"
201+
indoc! {r#"
189202
declare_clippy_lint! {{
190203
/// ### What it does
191204
///
@@ -199,11 +212,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
199212
/// ```rust
200213
/// // example code which does not raise clippy warning
201214
/// ```
215+
#[clippy::version = "{version}"]
202216
pub {name_upper},
203217
{category},
204-
\"default lint description\"
218+
"default lint description"
205219
}}
206-
"},
220+
"#},
221+
version = version,
207222
name_upper = name_upper,
208223
category = category,
209224
));

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
@@ -188,6 +188,7 @@ declare_clippy_lint! {
188188
/// ```rust
189189
/// // example code
190190
/// ```
191+
#[clippy::version = "1.29.0"]
191192
pub FOO_FUNCTIONS,
192193
pedantic,
193194
"function named `foo`, which is not a descriptive name"
@@ -198,6 +199,10 @@ declare_clippy_lint! {
198199
section. This is the default documentation style and will be displayed
199200
[like this][example_lint_page]. To render and open this documentation locally
200201
in a browser, run `cargo dev serve`.
202+
* The `#[clippy::version]` attribute will be rendered as part of the lint documentation.
203+
The value should be set to the current Rust version that the lint is developed in,
204+
it can be retrieved by running `rustc -vV` in the rust-clippy directory. The version
205+
is listed under *release*. (Use the version without the `-nightly`) suffix.
201206
* `FOO_FUNCTIONS` is the name of our lint. Be sure to follow the
202207
[lint naming guidelines][lint_naming] here when naming your lint.
203208
In short, the name should state the thing that is being checked for and
@@ -500,6 +505,7 @@ declare_clippy_lint! {
500505
/// // Good
501506
/// Insert a short example of improved code that doesn't trigger the lint
502507
/// ```
508+
#[clippy::version = "1.29.0"]
503509
pub FOO_FUNCTIONS,
504510
pedantic,
505511
"function named `foo`, which is not a descriptive name"

0 commit comments

Comments
 (0)