Skip to content

Commit b0ce81c

Browse files
committed
clippy_dev: Remove print option from update_lints
1 parent d2ff070 commit b0ce81c

File tree

2 files changed

+20
-96
lines changed

2 files changed

+20
-96
lines changed

clippy_dev/src/main.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ fn main() {
2727
allow_no_vcs,
2828
} => dogfood::dogfood(fix, allow_dirty, allow_staged, allow_no_vcs),
2929
DevCommand::Fmt { check, verbose } => fmt::run(check, verbose),
30-
DevCommand::UpdateLints { print_only, check } => {
31-
if print_only {
32-
update_lints::print_lints();
33-
} else {
34-
update_lints::update(utils::UpdateMode::from_check(check));
35-
}
36-
},
30+
DevCommand::UpdateLints { check } => update_lints::update(utils::UpdateMode::from_check(check)),
3731
DevCommand::NewLint {
3832
pass,
3933
name,
@@ -145,11 +139,6 @@ enum DevCommand {
145139
/// * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod` {n}
146140
/// * all lints are registered in the lint store
147141
UpdateLints {
148-
#[arg(long)]
149-
/// Print a table of lints to STDOUT
150-
///
151-
/// This does not include deprecated and internal lints. (Does not modify any files)
152-
print_only: bool,
153142
#[arg(long)]
154143
/// Checks that `cargo dev update_lints` has been run. Used on CI.
155144
check: bool,

clippy_dev/src/update_lints.rs

+19-84
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::utils::{
22
File, FileAction, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, panic_file, update_text_region_fn,
33
};
44
use itertools::Itertools;
5-
use std::collections::{HashMap, HashSet};
5+
use std::collections::HashSet;
66
use std::fmt::Write;
77
use std::fs::OpenOptions;
88
use std::ops::Range;
@@ -106,24 +106,6 @@ pub fn generate_lint_files(
106106
);
107107
}
108108

109-
pub fn print_lints() {
110-
let lints = find_lint_decls();
111-
let lint_count = lints.len();
112-
let grouped_by_lint_group = Lint::by_lint_group(lints.into_iter());
113-
114-
for (lint_group, mut lints) in grouped_by_lint_group {
115-
println!("\n## {lint_group}");
116-
117-
lints.sort_by_key(|l| l.name.clone());
118-
119-
for lint in lints {
120-
println!("* [{}]({DOCS_LINK}#{}) ({})", lint.name, lint.name, lint.desc);
121-
}
122-
}
123-
124-
println!("there are {lint_count} lints");
125-
}
126-
127109
fn round_to_fifty(count: usize) -> usize {
128110
count / 50 * 50
129111
}
@@ -133,19 +115,10 @@ fn round_to_fifty(count: usize) -> usize {
133115
pub struct Lint {
134116
pub name: String,
135117
pub group: String,
136-
pub desc: String,
137118
pub module: String,
138119
pub declaration_range: Range<usize>,
139120
}
140121

141-
impl Lint {
142-
/// Returns the lints in a `HashMap`, grouped by the different lint groups
143-
#[must_use]
144-
fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
145-
lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
146-
}
147-
}
148-
149122
#[derive(Clone, PartialEq, Eq, Debug)]
150123
pub struct DeprecatedLint {
151124
pub name: String,
@@ -185,7 +158,6 @@ pub fn find_lint_decls() -> Vec<Lint> {
185158
let mut contents = String::new();
186159
for (file, module) in read_src_with_module("clippy_lints/src".as_ref()) {
187160
parse_clippy_lint_decls(
188-
file.path(),
189161
File::open_read_to_cleared_string(file.path(), &mut contents),
190162
&module,
191163
&mut lints,
@@ -230,7 +202,7 @@ fn read_src_with_module(src_root: &Path) -> impl use<'_> + Iterator<Item = (DirE
230202
}
231203

232204
/// Parse a source file looking for `declare_clippy_lint` macro invocations.
233-
fn parse_clippy_lint_decls(path: &Path, contents: &str, module: &str, lints: &mut Vec<Lint>) {
205+
fn parse_clippy_lint_decls(contents: &str, module: &str, lints: &mut Vec<Lint>) {
234206
#[allow(clippy::enum_glob_use)]
235207
use Token::*;
236208
#[rustfmt::skip]
@@ -239,21 +211,20 @@ fn parse_clippy_lint_decls(path: &Path, contents: &str, module: &str, lints: &mu
239211
Bang, OpenBrace, AnyDoc,
240212
// #[clippy::version = "version"]
241213
Pound, OpenBracket, Ident("clippy"), DoubleColon, Ident("version"), Eq, LitStr, CloseBracket,
242-
// pub NAME, GROUP, "description"
243-
Ident("pub"), CaptureIdent, Comma, CaptureIdent, Comma, CaptureLitStr,
214+
// pub NAME, GROUP,
215+
Ident("pub"), CaptureIdent, Comma, CaptureIdent, Comma,
244216
];
245217

246218
let mut searcher = RustSearcher::new(contents);
247219
while searcher.find_token(Ident("declare_clippy_lint")) {
248220
let start = searcher.pos() as usize - "declare_clippy_lint".len();
249-
let (mut name, mut group, mut desc) = ("", "", "");
250-
if searcher.match_tokens(DECL_TOKENS, &mut [&mut name, &mut group, &mut desc])
221+
let (mut name, mut group) = ("", "");
222+
if searcher.match_tokens(DECL_TOKENS, &mut [&mut name, &mut group])
251223
&& searcher.find_token(CloseBrace)
252224
{
253225
lints.push(Lint {
254226
name: name.to_lowercase(),
255227
group: group.into(),
256-
desc: parse_str_single_line(path, desc),
257228
module: module.into(),
258229
declaration_range: start..searcher.pos() as usize,
259230
});
@@ -397,61 +368,25 @@ mod tests {
397368
}
398369
"#;
399370
let mut result = Vec::new();
400-
parse_clippy_lint_decls("".as_ref(), CONTENTS, "module_name", &mut result);
371+
parse_clippy_lint_decls(CONTENTS, "module_name", &mut result);
401372
for r in &mut result {
402373
r.declaration_range = Range::default();
403374
}
404375

405376
let expected = vec![
406-
Lint::new(
407-
"ptr_arg",
408-
"style",
409-
"\"really long text\"",
410-
"module_name",
411-
Range::default(),
412-
),
413-
Lint::new(
414-
"doc_markdown",
415-
"pedantic",
416-
"\"single line\"",
417-
"module_name",
418-
Range::default(),
419-
),
377+
Lint {
378+
name: "ptr_arg".into(),
379+
group: "style".into(),
380+
module: "module_name".into(),
381+
declaration_range: Range::default(),
382+
},
383+
Lint {
384+
name: "doc_markdown".into(),
385+
group: "pedantic".into(),
386+
module: "module_name".into(),
387+
declaration_range: Range::default(),
388+
},
420389
];
421390
assert_eq!(expected, result);
422391
}
423-
424-
#[test]
425-
fn test_by_lint_group() {
426-
let lints = vec![
427-
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
428-
Lint::new(
429-
"should_assert_eq2",
430-
"group2",
431-
"\"abc\"",
432-
"module_name",
433-
Range::default(),
434-
),
435-
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
436-
];
437-
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
438-
expected.insert(
439-
"group1".to_string(),
440-
vec![
441-
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
442-
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
443-
],
444-
);
445-
expected.insert(
446-
"group2".to_string(),
447-
vec![Lint::new(
448-
"should_assert_eq2",
449-
"group2",
450-
"\"abc\"",
451-
"module_name",
452-
Range::default(),
453-
)],
454-
);
455-
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
456-
}
457392
}

0 commit comments

Comments
 (0)