Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 82bf659

Browse files
committed
Ensure that symbols list stays sorted
1 parent bb724f3 commit 82bf659

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

clippy_dev/src/fmt.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use crate::utils::{ClippyInfo, ErrAction, UpdateMode, panic_action, run_with_args_split, run_with_output};
1+
use crate::utils::{
2+
ClippyInfo, ErrAction, FileUpdater, UpdateMode, UpdateStatus, panic_action, run_with_args_split, run_with_output,
3+
};
24
use itertools::Itertools;
35
use rustc_lexer::{TokenKind, tokenize};
6+
use std::fmt::Write;
47
use std::fs;
58
use std::io::{self, Read};
69
use std::ops::ControlFlow;
@@ -225,6 +228,38 @@ fn fmt_conf(check: bool) -> Result<(), Error> {
225228
Ok(())
226229
}
227230

231+
/// Format the symbols list
232+
fn fmt_syms(update_mode: UpdateMode) {
233+
FileUpdater::default().update_file_checked(
234+
"cargo dev fmt",
235+
update_mode,
236+
"clippy_utils/src/sym.rs",
237+
&mut |_, text: &str, new_text: &mut String| {
238+
let (pre, conf) = text.split_once("generate! {\n").expect("can't find generate! call");
239+
let (conf, post) = conf.split_once("\n}\n").expect("can't find end of generate! call");
240+
let mut lines = conf
241+
.lines()
242+
.map(|line| {
243+
let line = line.trim();
244+
line.strip_suffix(',').unwrap_or(line).trim_end()
245+
})
246+
.collect::<Vec<_>>();
247+
lines.sort_unstable();
248+
write!(
249+
new_text,
250+
"{pre}generate! {{\n {},\n}}\n{post}",
251+
lines.join(",\n "),
252+
)
253+
.unwrap();
254+
if text == new_text {
255+
UpdateStatus::Unchanged
256+
} else {
257+
UpdateStatus::Changed
258+
}
259+
},
260+
);
261+
}
262+
228263
fn run_rustfmt(clippy: &ClippyInfo, update_mode: UpdateMode) {
229264
let mut rustfmt_path = String::from_utf8(run_with_output(
230265
"rustup which rustfmt",
@@ -337,7 +372,7 @@ pub fn run(clippy: &ClippyInfo, update_mode: UpdateMode) {
337372
return;
338373
}
339374
run_rustfmt(clippy, update_mode);
340-
375+
fmt_syms(update_mode);
341376
if let Err(e) = fmt_conf(update_mode.is_check()) {
342377
e.display();
343378
process::exit(1);

clippy_utils/src/sym.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ macro_rules! generate {
3131

3232
// List of extra symbols to be included in Clippy (for example, as `sym::ambiguous_glob_reexports`).
3333
// An alternative content can be specified using a colon after the symbol name.
34+
//
35+
// `cargo dev fmt` ensures that the content of the `generate!()` macro call stays sorted.
3436
generate! {
3537
AsyncReadExt,
3638
AsyncWriteExt,

0 commit comments

Comments
 (0)