Skip to content

Use replace_region_in_file for creating the lint list #4206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,26 @@ fn update_lints(update_mode: &UpdateMode) {
let mut sorted_usable_lints = usable_lints.clone();
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());

std::fs::write(
let mut file_change = replace_region_in_file(
"../src/lintlist/mod.rs",
&format!(
"\
//! This file is managed by `util/dev update_lints`. Do not edit.

pub mod lint;
pub use lint::Level;
pub use lint::Lint;
pub use lint::LINT_LEVELS;

pub const ALL_LINTS: [Lint; {}] = {:#?};\n",
sorted_usable_lints.len(),
sorted_usable_lints
),
"begin lint list",
"end lint list",
false,
update_mode == &UpdateMode::Change,
|| {
format!(
"pub const ALL_LINTS: [Lint; {}] = {:#?};",
sorted_usable_lints.len(),
sorted_usable_lints
)
.lines()
.map(ToString::to_string)
.collect::<Vec<_>>()
},
)
.expect("can write to file");
.changed;

let mut file_change = replace_region_in_file(
file_change |= replace_region_in_file(
"../README.md",
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
"",
Expand Down
25 changes: 17 additions & 8 deletions src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ pub use lint::Level;
pub use lint::Lint;
pub use lint::LINT_LEVELS;

pub const ALL_LINTS: [Lint; 304] = [
// begin lint list, do not remove this comment, it’s used in `update_lints`
pub const ALL_LINTS: [Lint; 305] = [
Lint {
name: "absurd_extreme_comparisons",
group: "correctness",
Expand Down Expand Up @@ -251,13 +252,6 @@ pub const ALL_LINTS: [Lint; 304] = [
deprecation: None,
module: "collapsible_if",
},
Lint {
name: "const_static_lifetime",
group: "style",
desc: "Using explicit `\'static` lifetime for constants when elision rules would allow omitting them.",
deprecation: None,
module: "const_static_lifetime",
},
Lint {
name: "copy_iterator",
group: "pedantic",
Expand Down Expand Up @@ -762,6 +756,13 @@ pub const ALL_LINTS: [Lint; 304] = [
deprecation: None,
module: "arithmetic",
},
Lint {
name: "integer_division",
group: "pedantic",
desc: "integer division may cause loss of precision",
deprecation: None,
module: "integer_division",
},
Lint {
name: "into_iter_on_array",
group: "correctness",
Expand Down Expand Up @@ -1525,6 +1526,13 @@ pub const ALL_LINTS: [Lint; 304] = [
deprecation: None,
module: "redundant_pattern_matching",
},
Lint {
name: "redundant_static_lifetimes",
group: "style",
desc: "Using explicit `\'static` lifetime for constants or statics when elision rules would allow omitting them.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the backward slash \ necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but this Regex:

let lints = DEC_CLIPPY_LINT_RE
.captures_iter(content)
.map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, filename));

probably adds it, while parsing the description of the lint. This could be handled here

desc: NL_ESCAPE_RE.replace(&desc.replace("\\\"", "\""), "").to_string(),

just like \" is. 🤔

deprecation: None,
module: "redundant_static_lifetimes",
},
Lint {
name: "ref_in_deref",
group: "complexity",
Expand Down Expand Up @@ -2135,3 +2143,4 @@ pub const ALL_LINTS: [Lint; 304] = [
module: "unicode",
},
];
// end lint list, do not remove this comment, it’s used in `update_lints`