Skip to content

Commit 3b64ca9

Browse files
committed
Auto merge of rust-lang#13173 - Jarcho:conf_order, r=xFrednet
Misc changes to `clippy_config` Contains part of rust-lang#13084 Changes include: * Sort config list and each configs lint list. * Add default text for the two configs that were missing it. * Switch the lint list in the configs to an attribute. * Make `dev fmt` sort the config list. r? `@xFrednet` changelog: none
2 parents f7db895 + 78a750e commit 3b64ca9

File tree

8 files changed

+671
-561
lines changed

8 files changed

+671
-561
lines changed

book/src/lint_configuration.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Suppress lints whenever the suggested change would cause breakage for other crat
364364

365365

366366
## `await-holding-invalid-types`
367-
367+
The list of types which may not be held across an await point.
368368

369369
**Default Value:** `[]`
370370

@@ -668,6 +668,8 @@ crate. For example, `pub(crate)` items.
668668
## `msrv`
669669
The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
670670

671+
**Default Value:** `current version`
672+
671673
---
672674
**Affected lints:**
673675
* [`allow_attributes`](https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes)
@@ -862,6 +864,8 @@ The maximum number of lines a function or method can have
862864
The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
863865
reference. By default there is no limit
864866

867+
**Default Value:** `target_pointer_width * 2`
868+
865869
---
866870
**Affected lints:**
867871
* [`trivially_copy_pass_by_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref)

clippy_config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
itertools = "0.12"
910
rustc-semver = "1.1"
1011
serde = { version = "1.0", features = ["derive"] }
1112
toml = "0.7.3"

clippy_config/src/conf.rs

Lines changed: 360 additions & 364 deletions
Large diffs are not rendered by default.

clippy_config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(rustc_private, let_chains)]
1+
#![feature(rustc_private, array_windows, let_chains)]
22
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
33
#![warn(
44
trivial_casts,

clippy_config/src/metadata.rs

Lines changed: 11 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use std::fmt::{self, Write};
1+
use itertools::Itertools;
2+
use std::fmt;
23

34
#[derive(Debug, Clone, Default)]
45
pub struct ClippyConfiguration {
56
pub name: String,
67
pub default: String,
7-
pub lints: Vec<String>,
8-
pub doc: String,
8+
pub lints: &'static [&'static str],
9+
pub doc: &'static str,
910
pub deprecation_reason: Option<&'static str>,
1011
}
1112

@@ -20,102 +21,20 @@ impl fmt::Display for ClippyConfiguration {
2021
}
2122

2223
impl ClippyConfiguration {
23-
pub fn new(
24-
name: &'static str,
25-
default: String,
26-
doc_comment: &'static str,
27-
deprecation_reason: Option<&'static str>,
28-
) -> Self {
29-
let (mut lints, doc) = parse_config_field_doc(doc_comment)
30-
.unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
31-
32-
lints.sort();
33-
34-
Self {
35-
name: to_kebab(name),
36-
lints,
37-
doc,
38-
default,
39-
deprecation_reason,
40-
}
41-
}
42-
4324
pub fn to_markdown_paragraph(&self) -> String {
44-
let mut out = format!(
45-
"## `{}`\n{}\n\n",
25+
format!(
26+
"## `{}`\n{}\n\n**Default Value:** `{}`\n\n---\n**Affected lints:**\n{}\n\n",
4627
self.name,
47-
self.doc
48-
.lines()
49-
.map(|line| line.strip_prefix(" ").unwrap_or(line))
50-
.collect::<Vec<_>>()
51-
.join("\n"),
52-
);
53-
54-
if !self.default.is_empty() {
55-
write!(out, "**Default Value:** `{}`\n\n", self.default).unwrap();
56-
}
57-
58-
write!(
59-
out,
60-
"---\n**Affected lints:**\n{}\n\n",
61-
self.lints
62-
.iter()
63-
.map(|name| name.to_string().split_whitespace().next().unwrap().to_string())
64-
.map(|name| format!("* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
65-
.collect::<Vec<_>>()
66-
.join("\n"),
28+
self.doc.lines().map(|x| x.strip_prefix(' ').unwrap_or(x)).join("\n"),
29+
self.default,
30+
self.lints.iter().format_with("\n", |name, f| f(&format_args!(
31+
"* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"
32+
))),
6733
)
68-
.unwrap();
69-
70-
out
7134
}
7235

7336
pub fn to_markdown_link(&self) -> String {
7437
const BOOK_CONFIGS_PATH: &str = "https://doc.rust-lang.org/clippy/lint_configuration.html";
7538
format!("[`{}`]: {BOOK_CONFIGS_PATH}#{}", self.name, self.name)
7639
}
7740
}
78-
79-
/// This parses the field documentation of the config struct.
80-
///
81-
/// ```rust, ignore
82-
/// parse_config_field_doc(cx, "Lint: LINT_NAME_1, LINT_NAME_2. Papa penguin, papa penguin")
83-
/// ```
84-
///
85-
/// Would yield:
86-
/// ```rust, ignore
87-
/// Some(["lint_name_1", "lint_name_2"], "Papa penguin, papa penguin")
88-
/// ```
89-
fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
90-
const DOC_START: &str = " Lint: ";
91-
if doc_comment.starts_with(DOC_START)
92-
&& let Some(split_pos) = doc_comment.find('.')
93-
{
94-
let mut doc_comment = doc_comment.to_string();
95-
let mut documentation = doc_comment.split_off(split_pos);
96-
97-
// Extract lints
98-
doc_comment.make_ascii_lowercase();
99-
let lints: Vec<String> = doc_comment
100-
.split_off(DOC_START.len())
101-
.lines()
102-
.next()
103-
.unwrap()
104-
.split(", ")
105-
.map(str::to_string)
106-
.collect();
107-
108-
// Format documentation correctly
109-
// split off leading `.` from lint name list and indent for correct formatting
110-
documentation = documentation.trim_start_matches('.').trim().replace("\n ", "\n ");
111-
112-
Some((lints, documentation))
113-
} else {
114-
None
115-
}
116-
}
117-
118-
/// Transforms a given `snake_case_string` to a tasty `kebab-case-string`
119-
fn to_kebab(config_name: &str) -> String {
120-
config_name.replace('_', "-")
121-
}

0 commit comments

Comments
 (0)