summaryrefslogtreecommitdiff
path: root/cli/tools/lint
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-05-08 22:45:06 -0400
committerGitHub <noreply@github.com>2024-05-08 22:45:06 -0400
commit47f7bed677a6b72e873712de8f3988ea891710e4 (patch)
tree096549459b479cf1383e65c87b77e9f9482df258 /cli/tools/lint
parente6dc4dfbff25e77d2127591802229b4a74037d24 (diff)
chore: enable clippy::print_stdout and clippy::print_stderr (#23732)
1. Generally we should prefer to use the `log` crate. 2. I very often accidentally commit `eprintln`s. When we should use `println` or `eprintln`, it's not too bad to be a bit more verbose and ignore the lint rule.
Diffstat (limited to 'cli/tools/lint')
-rw-r--r--cli/tools/lint/mod.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs
index 03f5b8676..aeb919976 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -279,6 +279,7 @@ fn collect_lint_files(
.collect_file_patterns(files)
}
+#[allow(clippy::print_stdout)]
pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
let lint_rules = if maybe_rules_tags.is_none() {
rules::get_all_rules()
@@ -646,12 +647,12 @@ impl LintReporter for PrettyLintReporter {
}
}
- eprintln!("{}", d.display());
+ log::error!("{}", d.display());
}
fn visit_error(&mut self, file_path: &str, err: &AnyError) {
- eprintln!("Error linting: {file_path}");
- eprintln!(" {err}");
+ log::error!("Error linting: {file_path}");
+ log::error!(" {err}");
}
fn close(&mut self, check_count: usize) {
@@ -694,7 +695,7 @@ impl LintReporter for CompactLintReporter {
match d.range() {
Some((text_info, range)) => {
let line_and_column = text_info.line_and_column_display(range.start);
- eprintln!(
+ log::error!(
"{}: line {}, col {} - {} ({})",
d.specifier(),
line_and_column.line_number,
@@ -704,14 +705,14 @@ impl LintReporter for CompactLintReporter {
)
}
None => {
- eprintln!("{}: {} ({})", d.specifier(), d.message(), d.code())
+ log::error!("{}: {} ({})", d.specifier(), d.message(), d.code())
}
}
}
fn visit_error(&mut self, file_path: &str, err: &AnyError) {
- eprintln!("Error linting: {file_path}");
- eprintln!(" {err}");
+ log::error!("Error linting: {file_path}");
+ log::error!(" {err}");
}
fn close(&mut self, check_count: usize) {
@@ -812,7 +813,10 @@ impl LintReporter for JsonLintReporter {
fn close(&mut self, _check_count: usize) {
sort_diagnostics(&mut self.diagnostics);
let json = serde_json::to_string_pretty(&self);
- println!("{}", json.unwrap());
+ #[allow(clippy::print_stdout)]
+ {
+ println!("{}", json.unwrap());
+ }
}
}