Skip to content

Commit 3ed159f

Browse files
committed
Use replace_region_in_file for creating the lint list
1 parent bd39cea commit 3ed159f

File tree

2 files changed

+332
-322
lines changed

2 files changed

+332
-322
lines changed

clippy_dev/src/main.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,26 @@ fn update_lints(update_mode: &UpdateMode) {
9494
let mut sorted_usable_lints = usable_lints.clone();
9595
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
9696

97-
std::fs::write(
97+
let mut file_change = replace_region_in_file(
9898
"../src/lintlist/mod.rs",
99-
&format!(
100-
"\
101-
//! This file is managed by `util/dev update_lints`. Do not edit.
102-
103-
pub mod lint;
104-
pub use lint::Level;
105-
pub use lint::Lint;
106-
pub use lint::LINT_LEVELS;
107-
108-
pub const ALL_LINTS: [Lint; {}] = {:#?};\n",
109-
sorted_usable_lints.len(),
110-
sorted_usable_lints
111-
),
99+
"begin lint list",
100+
"end lint list",
101+
false,
102+
update_mode == &UpdateMode::Change,
103+
|| {
104+
format!(
105+
"pub const ALL_LINTS: [Lint; {}] = {:#?};",
106+
sorted_usable_lints.len(),
107+
sorted_usable_lints
108+
)
109+
.lines()
110+
.map(ToString::to_string)
111+
.collect::<Vec<_>>()
112+
},
112113
)
113-
.expect("can write to file");
114+
.changed;
114115

115-
let mut file_change = replace_region_in_file(
116+
file_change |= replace_region_in_file(
116117
"../README.md",
117118
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
118119
"",

0 commit comments

Comments
 (0)