Document new clippy::version
attribute and make it mandatory
This commit is contained in:
parent
8565fc468e
commit
23ed79260b
@ -12,6 +12,7 @@ opener = "0.5"
|
||||
regex = "1.5"
|
||||
shell-escape = "0.1"
|
||||
walkdir = "2.3"
|
||||
cargo_metadata = "0.12"
|
||||
|
||||
[features]
|
||||
deny-warnings = []
|
||||
|
@ -132,6 +132,18 @@ fn to_camel_case(name: &str) -> String {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_stabilisation_version() -> String {
|
||||
let mut command = cargo_metadata::MetadataCommand::new();
|
||||
command.no_deps();
|
||||
if let Ok(metadata) = command.exec() {
|
||||
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
|
||||
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
|
||||
}
|
||||
}
|
||||
|
||||
String::from("<TODO set version(see doc/adding_lints.md)")
|
||||
}
|
||||
|
||||
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
|
||||
let mut contents = format!(
|
||||
indoc! {"
|
||||
@ -178,6 +190,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
|
||||
},
|
||||
};
|
||||
|
||||
let version = get_stabilisation_version();
|
||||
let lint_name = lint.name;
|
||||
let category = lint.category;
|
||||
let name_camel = to_camel_case(lint.name);
|
||||
@ -212,7 +225,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
|
||||
});
|
||||
|
||||
result.push_str(&format!(
|
||||
indoc! {"
|
||||
indoc! {r#"
|
||||
declare_clippy_lint! {{
|
||||
/// ### What it does
|
||||
///
|
||||
@ -226,11 +239,13 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
|
||||
/// ```rust
|
||||
/// // example code which does not raise clippy warning
|
||||
/// ```
|
||||
#[clippy::version = "{version}"]
|
||||
pub {name_upper},
|
||||
{category},
|
||||
\"default lint description\"
|
||||
"default lint description"
|
||||
}}
|
||||
"},
|
||||
"#},
|
||||
version = version,
|
||||
name_upper = name_upper,
|
||||
category = category,
|
||||
));
|
||||
|
@ -18,7 +18,7 @@ static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
|
||||
r#"(?x)
|
||||
declare_clippy_lint!\s*[\{(]
|
||||
(?:\s+///.*)*
|
||||
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
|
||||
(?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])
|
||||
\s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
|
||||
(?P<cat>[a-z_]+)\s*,\s*
|
||||
"(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
|
||||
@ -496,6 +496,7 @@ fn test_parse_contents() {
|
||||
let result: Vec<Lint> = parse_contents(
|
||||
r#"
|
||||
declare_clippy_lint! {
|
||||
#[clippy::version = "Hello Clippy!"]
|
||||
pub PTR_ARG,
|
||||
style,
|
||||
"really long \
|
||||
@ -503,6 +504,7 @@ declare_clippy_lint! {
|
||||
}
|
||||
|
||||
declare_clippy_lint!{
|
||||
#[clippy::version = "Test version"]
|
||||
pub DOC_MARKDOWN,
|
||||
pedantic,
|
||||
"single line"
|
||||
@ -510,6 +512,7 @@ declare_clippy_lint!{
|
||||
|
||||
/// some doc comment
|
||||
declare_deprecated_lint! {
|
||||
#[clippy::version = "I'm a version"]
|
||||
pub SHOULD_ASSERT_EQ,
|
||||
"`assert!()` will be more flexible with RFC 2011"
|
||||
}
|
||||
|
@ -189,6 +189,7 @@ declare_clippy_lint! {
|
||||
/// ```rust
|
||||
/// // example code
|
||||
/// ```
|
||||
#[clippy::version = "1.29.0"]
|
||||
pub FOO_FUNCTIONS,
|
||||
pedantic,
|
||||
"function named `foo`, which is not a descriptive name"
|
||||
@ -199,6 +200,10 @@ declare_clippy_lint! {
|
||||
section. This is the default documentation style and will be displayed
|
||||
[like this][example_lint_page]. To render and open this documentation locally
|
||||
in a browser, run `cargo dev serve`.
|
||||
* The `#[clippy::version]` attribute will be rendered as part of the lint documentation.
|
||||
The value should be set to the current Rust version that the lint is developed in,
|
||||
it can be retrieved by running `rustc -vV` in the rust-clippy directory. The version
|
||||
is listed under *release*. (Use the version without the `-nightly`) suffix.
|
||||
* `FOO_FUNCTIONS` is the name of our lint. Be sure to follow the
|
||||
[lint naming guidelines][lint_naming] here when naming your lint.
|
||||
In short, the name should state the thing that is being checked for and
|
||||
@ -503,6 +508,7 @@ declare_clippy_lint! {
|
||||
/// // Good
|
||||
/// Insert a short example of improved code that doesn't trigger the lint
|
||||
/// ```
|
||||
#[clippy::version = "1.29.0"]
|
||||
pub FOO_FUNCTIONS,
|
||||
pedantic,
|
||||
"function named `foo`, which is not a descriptive name"
|
||||
|
Loading…
x
Reference in New Issue
Block a user