Skip to content

Commit 047e2da

Browse files
committed
Document new clippy::version attribute and make it mandatory
1 parent 3eb20d2 commit 047e2da

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-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+
rustc_version = "0.4"
1516

1617
[features]
1718
deny-warnings = []

clippy_dev/src/new_lint.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ fn to_camel_case(name: &str) -> String {
104104
.collect()
105105
}
106106

107+
fn get_stabilisation_version() -> String {
108+
let version = rustc_version::version().expect("Unable to determine rustc version with `rustc_version`");
109+
format!("{}.{}.0", version.major, version.minor)
110+
}
111+
107112
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
108113
let mut contents = format!(
109114
indoc! {"
@@ -150,6 +155,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
150155
},
151156
};
152157

158+
let version = get_stabilisation_version();
153159
let lint_name = lint.name;
154160
let pass_name = lint.pass;
155161
let category = lint.category;
@@ -185,7 +191,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
185191
});
186192

187193
result.push_str(&format!(
188-
indoc! {"
194+
indoc! {r#"
189195
declare_clippy_lint! {{
190196
/// ### What it does
191197
///
@@ -199,11 +205,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
199205
/// ```rust
200206
/// // example code which does not raise clippy warning
201207
/// ```
208+
#[clippy::version = "{version}"]
202209
pub {name_upper},
203210
{category},
204-
\"default lint description\"
211+
"default lint description"
205212
}}
206-
"},
213+
"#},
214+
version = version,
207215
name_upper = name_upper,
208216
category = category,
209217
));

clippy_dev/src/update_lints.rs

Lines changed: 1 addition & 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*[})]

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
//! The module transforms all lint names to ascii lowercase to ensure that we don't have mismatches
88
//! during any comparison or mapping. (Please take care of this, it's not fun to spend time on such
99
//! a simple mistake)
10+
//!
11+
//! ---
12+
//!
13+
//! So while implementing the version attribute we needed to get all versions that a lint was
14+
//! introduced... and I wrote a script for nushell, my first script.. It's not pretty but special
15+
//! ```nu
16+
//! ls | where name =~ "rust-" | select name | format {name}/lints.json | each { open $it | select id | insert version $it | str substring "5,11" version} | group-by id | rotate counter-clockwise id version | update version {get version | first 1} | flatten | select id version | save "lint-version.csv"
17+
//! ```
18+
//! And it works, just run it on the `gh-pages` branch to get a beautiful csv file.
1019
1120
use if_chain::if_chain;
1221
use rustc_ast as ast;

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)