diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-05-08 22:45:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 22:45:06 -0400 |
commit | 47f7bed677a6b72e873712de8f3988ea891710e4 (patch) | |
tree | 096549459b479cf1383e65c87b77e9f9482df258 /cli | |
parent | e6dc4dfbff25e77d2127591802229b4a74037d24 (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')
-rw-r--r-- | cli/args/flags.rs | 18 | ||||
-rw-r--r-- | cli/args/mod.rs | 9 | ||||
-rw-r--r-- | cli/bench/main.rs | 3 | ||||
-rw-r--r-- | cli/file_fetcher.rs | 2 | ||||
-rw-r--r-- | cli/main.rs | 6 | ||||
-rw-r--r-- | cli/mainrt.rs | 4 | ||||
-rw-r--r-- | cli/ops/jupyter.rs | 4 | ||||
-rw-r--r-- | cli/tools/bench/reporters.rs | 4 | ||||
-rw-r--r-- | cli/tools/bundle.rs | 5 | ||||
-rw-r--r-- | cli/tools/coverage/reporter.rs | 5 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 5 | ||||
-rw-r--r-- | cli/tools/info.rs | 1 | ||||
-rw-r--r-- | cli/tools/jupyter/install.rs | 6 | ||||
-rw-r--r-- | cli/tools/jupyter/server.rs | 73 | ||||
-rw-r--r-- | cli/tools/lint/mod.rs | 20 | ||||
-rw-r--r-- | cli/tools/registry/diagnostics.rs | 18 | ||||
-rw-r--r-- | cli/tools/registry/mod.rs | 44 | ||||
-rw-r--r-- | cli/tools/repl/editor.rs | 2 | ||||
-rw-r--r-- | cli/tools/repl/mod.rs | 7 | ||||
-rw-r--r-- | cli/tools/task.rs | 100 | ||||
-rw-r--r-- | cli/tools/test/channel.rs | 2 | ||||
-rw-r--r-- | cli/tools/test/mod.rs | 2 | ||||
-rw-r--r-- | cli/tools/test/reporters/dot.rs | 2 | ||||
-rw-r--r-- | cli/tools/test/reporters/tap.rs | 2 | ||||
-rw-r--r-- | cli/tools/upgrade.rs | 18 | ||||
-rw-r--r-- | cli/util/file_watcher.rs | 4 | ||||
-rw-r--r-- | cli/util/v8.rs | 2 | ||||
-rw-r--r-- | cli/worker.rs | 2 |
28 files changed, 224 insertions, 146 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 0ef02be39..dca9cfa49 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -3889,6 +3889,7 @@ fn eval_parse(flags: &mut Flags, matches: &mut ArgMatches) { // TODO(@satyarohith): remove this flag in 2.0. let as_typescript = matches.get_flag("ts"); + #[allow(clippy::print_stderr)] if as_typescript { eprintln!( "⚠️ {}", @@ -4218,6 +4219,8 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) { let no_run = matches.get_flag("no-run"); let trace_leaks = matches.get_flag("trace-ops") || matches.get_flag("trace-leaks"); + + #[allow(clippy::print_stderr)] if trace_leaks && matches.get_flag("trace-ops") { // We can't change this to use the log crate because its not configured // yet at this point since the flags haven't been parsed. This flag is @@ -4267,10 +4270,17 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) { // yet at this point since the flags haven't been parsed. This flag is // deprecated though so it's not worth changing the code to use the log // crate here and this is only done for testing anyway. - eprintln!( - "⚠️ {}", - crate::colors::yellow("The `--jobs` flag is deprecated and will be removed in Deno 2.0.\nUse the `--parallel` flag with possibly the `DENO_JOBS` environment variable instead.\nLearn more at: https://docs.deno.com/runtime/manual/basics/env_variables"), - ); + #[allow(clippy::print_stderr)] + { + eprintln!( + "⚠️ {}", + crate::colors::yellow(concat!( + "The `--jobs` flag is deprecated and will be removed in Deno 2.0.\n", + "Use the `--parallel` flag with possibly the `DENO_JOBS` environment variable instead.\n", + "Learn more at: https://docs.deno.com/runtime/manual/basics/env_variables" + )), + ); + } if let Some(value) = matches.remove_one::<NonZeroUsize>("jobs") { Some(value) } else { diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 3b5d79ef3..bca7cc0f6 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -747,9 +747,12 @@ impl CliOptions { format!("for: {}", insecure_allowlist.join(", ")) }; let msg = - format!("DANGER: TLS certificate validation is disabled {domains}"); - // use eprintln instead of log::warn so this always gets shown - eprintln!("{}", colors::yellow(msg)); + format!("DANGER: TLS certificate validation is disabled {}", domains); + #[allow(clippy::print_stderr)] + { + // use eprintln instead of log::warn so this always gets shown + eprintln!("{}", colors::yellow(msg)); + } } let maybe_lockfile = maybe_lockfile.filter(|_| !force_global_cache); diff --git a/cli/bench/main.rs b/cli/bench/main.rs index 9bae6fab6..8f0627558 100644 --- a/cli/bench/main.rs +++ b/cli/bench/main.rs @@ -1,5 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +#![allow(clippy::print_stdout)] +#![allow(clippy::print_stderr)] + use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::Value; diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 01e1e3158..eda579b2b 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -739,6 +739,8 @@ async fn fetch_no_follow<'a>( Ok(FetchOnceResult::Code(body, result_headers)) } +#[allow(clippy::print_stdout)] +#[allow(clippy::print_stderr)] #[cfg(test)] mod tests { use crate::cache::GlobalHttpCache; diff --git a/cli/main.rs b/cli/main.rs index 3b103e780..4f866ee21 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -235,6 +235,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> { handle.await? } +#[allow(clippy::print_stderr)] fn setup_panic_hook() { // This function does two things inside of the panic hook: // - Tokio does not exit the process when a task panics, so we define a custom @@ -259,6 +260,7 @@ fn setup_panic_hook() { })); } +#[allow(clippy::print_stderr)] fn exit_with_message(message: &str, code: i32) -> ! { eprintln!( "{}: {}", @@ -289,6 +291,7 @@ fn exit_for_error(error: AnyError) -> ! { exit_with_message(&error_string, error_code); } +#[allow(clippy::print_stderr)] pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) { eprintln!( "Unstable API '{api_name}'. The `--unstable-{}` flag must be provided.", @@ -298,6 +301,7 @@ pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) { } // TODO(bartlomieju): remove when `--unstable` flag is removed. +#[allow(clippy::print_stderr)] pub(crate) fn unstable_warn_cb(feature: &str, api_name: &str) { eprintln!( "⚠️ {}", @@ -369,7 +373,9 @@ fn resolve_flags_and_init( // TODO(bartlomieju): remove when `--unstable` flag is removed. if flags.unstable_config.legacy_flag_enabled { + #[allow(clippy::print_stderr)] if matches!(flags.subcommand, DenoSubcommand::Check(_)) { + // can't use log crate because that's not setup yet eprintln!( "⚠️ {}", colors::yellow( diff --git a/cli/mainrt.rs b/cli/mainrt.rs index 59efa026c..6a363c04b 100644 --- a/cli/mainrt.rs +++ b/cli/mainrt.rs @@ -36,6 +36,7 @@ use std::env::current_exe; use crate::args::Flags; +#[allow(clippy::print_stderr)] pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) { eprintln!( "Unstable API '{api_name}'. The `--unstable-{}` flag must be provided.", @@ -44,6 +45,7 @@ pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) { std::process::exit(70); } +#[allow(clippy::print_stderr)] fn exit_with_message(message: &str, code: i32) -> ! { eprintln!( "{}: {}", @@ -57,7 +59,7 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T { match result { Ok(value) => value, Err(error) => { - let mut error_string = format!("{error:?}"); + let mut error_string = format!("{:?}", error); if let Some(e) = error.downcast_ref::<JsError>() { error_string = format_js_error(e); diff --git a/cli/ops/jupyter.rs b/cli/ops/jupyter.rs index e7e206de5..1c60bc2bc 100644 --- a/cli/ops/jupyter.rs +++ b/cli/ops/jupyter.rs @@ -76,13 +76,13 @@ pub fn op_print( if is_err { if let Err(err) = sender.send(StdioMsg::Stderr(msg.into())) { - eprintln!("Failed to send stderr message: {}", err); + log::error!("Failed to send stderr message: {}", err); } return Ok(()); } if let Err(err) = sender.send(StdioMsg::Stdout(msg.into())) { - eprintln!("Failed to send stdout message: {}", err); + log::error!("Failed to send stdout message: {}", err); } Ok(()) } diff --git a/cli/tools/bench/reporters.rs b/cli/tools/bench/reporters.rs index 9cc035f8f..b5229cf0a 100644 --- a/cli/tools/bench/reporters.rs +++ b/cli/tools/bench/reporters.rs @@ -50,6 +50,7 @@ impl JsonReporter { } } +#[allow(clippy::print_stdout)] impl BenchReporter for JsonReporter { fn report_group_summary(&mut self) {} #[cold] @@ -58,7 +59,7 @@ impl BenchReporter for JsonReporter { fn report_end(&mut self, _report: &BenchReport) { match write_json_to_stdout(self) { Ok(_) => (), - Err(e) => println!("{e}"), + Err(e) => println!("{}", e), } } @@ -118,6 +119,7 @@ impl ConsoleReporter { } } +#[allow(clippy::print_stdout)] impl BenchReporter for ConsoleReporter { #[cold] fn report_plan(&mut self, plan: &BenchPlan) { diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index 7701b6024..ef058f0d0 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -125,7 +125,10 @@ async fn bundle_action( ); } } else { - println!("{}", bundle_output.code); + #[allow(clippy::print_stdout)] + { + println!("{}", bundle_output.code); + } } Ok(()) } diff --git a/cli/tools/coverage/reporter.rs b/cli/tools/coverage/reporter.rs index f86fd186f..f6f8144a4 100644 --- a/cli/tools/coverage/reporter.rs +++ b/cli/tools/coverage/reporter.rs @@ -103,6 +103,7 @@ struct SummaryCoverageReporter { file_reports: Vec<(CoverageReport, String)>, } +#[allow(clippy::print_stdout)] impl SummaryCoverageReporter { pub fn new() -> SummaryCoverageReporter { SummaryCoverageReporter { @@ -166,6 +167,7 @@ impl SummaryCoverageReporter { } } +#[allow(clippy::print_stdout)] impl CoverageReporter for SummaryCoverageReporter { fn report( &mut self, @@ -312,6 +314,7 @@ impl DetailedCoverageReporter { } } +#[allow(clippy::print_stdout)] impl CoverageReporter for DetailedCoverageReporter { fn report( &mut self, @@ -416,7 +419,7 @@ impl CoverageReporter for HtmlCoverageReporter { ) .unwrap(); - println!("HTML coverage report has been generated at {}", root_report); + log::info!("HTML coverage report has been generated at {}", root_report); } } diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index b16639f99..ef3d48cb5 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -396,8 +396,8 @@ async fn format_source_files( } Err(e) => { let _g = output_lock.lock(); - eprintln!("Error formatting: {}", file_path.to_string_lossy()); - eprintln!(" {e}"); + log::error!("Error formatting: {}", file_path.to_string_lossy()); + log::error!(" {e}"); } } Ok(()) @@ -495,6 +495,7 @@ fn format_stdin(fmt_options: FmtOptions, ext: &str) -> Result<(), AnyError> { let file_path = PathBuf::from(format!("_stdin.{ext}")); let formatted_text = format_file(&file_path, &source, &fmt_options.options)?; if fmt_options.check { + #[allow(clippy::print_stdout)] if formatted_text.is_some() { println!("Not formatted stdin"); } diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 7c1d6761a..19975571b 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -97,6 +97,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { Ok(()) } +#[allow(clippy::print_stdout)] fn print_cache_info( factory: &CliFactory, json: bool, diff --git a/cli/tools/jupyter/install.rs b/cli/tools/jupyter/install.rs index 0c9b8b3e6..69a75837e 100644 --- a/cli/tools/jupyter/install.rs +++ b/cli/tools/jupyter/install.rs @@ -27,13 +27,13 @@ pub fn status() -> Result<(), AnyError> { if let Some(specs) = json_output.get("kernelspecs") { if let Some(specs_obj) = specs.as_object() { if specs_obj.contains_key("deno") { - println!("✅ Deno kernel already installed"); + log::info!("✅ Deno kernel already installed"); return Ok(()); } } } - println!("ℹ️ Deno kernel is not yet installed, run `deno jupyter --install` to set it up"); + log::warn!("ℹ️ Deno kernel is not yet installed, run `deno jupyter --install` to set it up"); Ok(()) } @@ -108,6 +108,6 @@ pub fn install() -> Result<(), AnyError> { } let _ = std::fs::remove_dir(temp_dir); - println!("✅ Deno kernelspec installed successfully."); + log::info!("✅ Deno kernelspec installed successfully."); Ok(()) } diff --git a/cli/tools/jupyter/server.rs b/cli/tools/jupyter/server.rs index 2107dcfbf..4021cf6a3 100644 --- a/cli/tools/jupyter/server.rs +++ b/cli/tools/jupyter/server.rs @@ -75,7 +75,7 @@ impl JupyterServer { let handle1 = deno_core::unsync::spawn(async move { if let Err(err) = Self::handle_heartbeat(&mut heartbeat).await { - eprintln!("Heartbeat error: {}", err); + log::error!("Heartbeat error: {}", err); } }); @@ -85,14 +85,14 @@ impl JupyterServer { if let Err(err) = Self::handle_control(control_socket, cancel_handle).await { - eprintln!("Control error: {}", err); + log::error!("Control error: {}", err); } } }); let handle3 = deno_core::unsync::spawn(async move { if let Err(err) = server.handle_shell(shell_socket).await { - eprintln!("Shell error: {}", err); + log::error!("Shell error: {}", err); } }); @@ -137,7 +137,7 @@ impl JupyterServer { .await; if let Err(err) = result { - eprintln!("Output {} error: {}", name, err); + log::error!("Output {} error: {}", name, err); } } } @@ -166,10 +166,10 @@ impl JupyterServer { cancel_handle.cancel(); } "interrupt_request" => { - eprintln!("Interrupt request currently not supported"); + log::error!("Interrupt request currently not supported"); } _ => { - eprintln!( + log::error!( "Unrecognized control message type: {}", msg.message_type() ); @@ -307,7 +307,7 @@ impl JupyterServer { // We don't handle these messages } _ => { - eprintln!("Unrecognized shell message type: {}", msg.message_type()); + log::error!("Unrecognized shell message type: {}", msg.message_type()); } } @@ -386,12 +386,13 @@ impl JupyterServer { tokio::time::sleep(std::time::Duration::from_millis(5)).await; } else if let Some(exception_details) = exception_details { // Determine the exception value and name - let (name, message, stack) = - if let Some(exception) = exception_details.exception { - let result = self - .repl_session - .call_function_on_args( - r#" + let (name, message, stack) = if let Some(exception) = + exception_details.exception + { + let result = self + .repl_session + .call_function_on_args( + r#" function(object) { if (object instanceof Error) { const name = "name" in object ? String(object.name) : ""; @@ -404,32 +405,32 @@ impl JupyterServer { } } "# - .into(), - &[exception], - ) - .await?; + .into(), + &[exception], + ) + .await?; - match result.result.value { - Some(serde_json::Value::String(str)) => { - if let Ok(object) = - serde_json::from_str::<HashMap<String, String>>(&str) - { - let get = |k| object.get(k).cloned().unwrap_or_default(); - (get("name"), get("message"), get("stack")) - } else { - eprintln!("Unexpected result while parsing JSON {str}"); - ("".into(), "".into(), "".into()) - } - } - _ => { - eprintln!("Unexpected result while parsing exception {result:?}"); + match result.result.value { + Some(serde_json::Value::String(str)) => { + if let Ok(object) = + serde_json::from_str::<HashMap<String, String>>(&str) + { + let get = |k| object.get(k).cloned().unwrap_or_default(); + (get("name"), get("message"), get("stack")) + } else { + log::error!("Unexpected result while parsing JSON {str}"); ("".into(), "".into(), "".into()) } } - } else { - eprintln!("Unexpectedly missing exception {exception_details:?}"); - ("".into(), "".into(), "".into()) - }; + _ => { + log::error!("Unexpected result while parsing exception {result:?}"); + ("".into(), "".into(), "".into()) + } + } + } else { + log::error!("Unexpectedly missing exception {exception_details:?}"); + ("".into(), "".into(), "".into()) + }; let stack = if stack.is_empty() { format!( @@ -546,7 +547,7 @@ async fn publish_result( if let Some(exception_details) = &response.exception_details { // If the object doesn't have a Jupyter.display method or it throws an // exception, we just ignore it and let the caller handle it. - eprintln!("Exception encountered: {}", exception_details.text); + log::error!("Exception encountered: {}", exception_details.text); return Ok(None); } 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()); + } } } diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index 38366ed7e..31f815767 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -38,7 +38,11 @@ impl PublishDiagnosticsCollector { diagnostics.sort_by_cached_key(|d| d.sorting_key()); for diagnostic in diagnostics { - eprint!("{}", diagnostic.display()); + // todo(https://github.com/denoland/deno_ast/issues/245): use log crate here + #[allow(clippy::print_stderr)] + { + eprint!("{}", diagnostic.display()); + } if matches!(diagnostic.level(), DiagnosticLevel::Error) { errors += 1; } @@ -48,18 +52,18 @@ impl PublishDiagnosticsCollector { } if errors > 0 { if has_slow_types_errors { - eprintln!( + log::error!( "This package contains errors for slow types. Fixing these errors will:\n" ); - eprintln!( + log::error!( " 1. Significantly improve your package users' type checking performance." ); - eprintln!(" 2. Improve the automatic documentation generation."); - eprintln!(" 3. Enable automatic .d.ts generation for Node.js."); - eprintln!( + log::error!(" 2. Improve the automatic documentation generation."); + log::error!(" 3. Enable automatic .d.ts generation for Node.js."); + log::error!( "\nDon't want to bother? You can choose to skip this step by" ); - eprintln!("providing the --allow-slow-types flag.\n"); + log::error!("providing the --allow-slow-types flag.\n"); } Err(anyhow!( diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index b8d31853b..1d1e5c54e 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -72,9 +72,10 @@ use super::check::TypeChecker; use self::paths::CollectedPublishPath; use self::tar::PublishableTarball; +#[allow(clippy::print_stderr)] fn ring_bell() { // ASCII code for the bell character. - print!("\x07"); + eprint!("\x07"); } struct PreparedPublishPackage { @@ -291,18 +292,19 @@ async fn get_auth_headers( .context("Failed to create interactive authorization")?; let auth_url = format!("{}?code={}", auth.verification_url, auth.code); - print!( - "Visit {} to authorize publishing of", - colors::cyan(&auth_url) - ); - if packages.len() > 1 { - println!(" {} packages", packages.len()); + let pkgs_text = if packages.len() > 1 { + format!("{} packages", packages.len()) } else { - println!(" @{}/{}", packages[0].scope, packages[0].package); - } + format!("@{}/{}", packages[0].scope, packages[0].package) + }; + log::warn!( + "Visit {} to authorize publishing of {}", + colors::cyan(&auth_url), + pkgs_text, + ); ring_bell(); - println!("{}", colors::gray("Waiting...")); + log::info!("{}", colors::gray("Waiting...")); let _ = open::that_detached(&auth_url); let interval = std::time::Duration::from_secs(auth.poll_interval); @@ -323,7 +325,7 @@ async fn get_auth_headers( .await; match res { Ok(res) => { - println!( + log::info!( "{} {} {}", colors::green("Authorization successful."), colors::gray("Authenticated as"), @@ -490,13 +492,13 @@ async fn ensure_scopes_and_packages_exist( }; ring_bell(); - println!( + log::warn!( "'@{}/{}' doesn't exist yet. Visit {} to create the package", &package.scope, &package.package, colors::cyan_with_underline(&create_package_url) ); - println!("{}", colors::gray("Waiting...")); + log::warn!("{}", colors::gray("Waiting...")); let _ = open::that_detached(&create_package_url); let package_api_url = api::get_package_api_url( @@ -510,7 +512,7 @@ async fn ensure_scopes_and_packages_exist( let response = client.get(&package_api_url).send().await?; if response.status() == 200 { let name = format!("@{}/{}", package.scope, package.package); - println!("Package {} created", colors::green(name)); + log::info!("Package {} created", colors::green(name)); break; } } @@ -615,7 +617,7 @@ async fn publish_package( provenance: bool, ) -> Result<(), AnyError> { let client = http_client.client()?; - println!( + log::info!( "{} @{}/{}@{} ...", colors::intense_blue("Publishing"), package.scope, @@ -649,7 +651,7 @@ async fn publish_package( ) .unwrap(); if task.status == "success" { - println!( + log::info!( "{} @{}/{}@{}", colors::yellow("Warning: Skipping, already published"), package.scope, @@ -658,7 +660,7 @@ async fn publish_package( ); return Ok(()); } - println!( + log::info!( "{} @{}/{}@{}", colors::yellow("Already uploaded, waiting for publishing"), package.scope, @@ -711,7 +713,7 @@ async fn publish_package( ); } - println!( + log::info!( "{} @{}/{}@{}", colors::green("Successfully published"), package.scope, @@ -748,7 +750,7 @@ async fn publish_package( let bundle = provenance::generate_provenance(subject).await?; let tlog_entry = &bundle.verification_material.tlog_entries[0]; - println!("{}", + log::info!("{}", colors::green(format!( "Provenance transparency log available at https://search.sigstore.dev/?logIndex={}", tlog_entry.log_index @@ -768,7 +770,7 @@ async fn publish_package( .await?; } - println!( + log::info!( "{}", colors::gray(format!( "Visit {}@{}/{}@{} for details", @@ -798,7 +800,7 @@ async fn prepare_packages_for_publishing( let cli_options = cli_factory.cli_options(); if members.len() > 1 { - println!("Publishing a workspace..."); + log::info!("Publishing a workspace..."); } // create the module graph diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index 9cb3cd1c2..dbc9bce70 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -490,7 +490,7 @@ impl ReplEditor { } self.errored_on_history_save.store(true, Relaxed); - eprintln!("Unable to save history file: {e}"); + log::warn!("Unable to save history file: {}", e); } } } diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 8847bee52..c29e29e71 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -40,6 +40,7 @@ struct Repl { message_handler: RustylineSyncMessageHandler, } +#[allow(clippy::print_stdout)] impl Repl { async fn run(&mut self) -> Result<(), AnyError> { loop { @@ -61,7 +62,7 @@ impl Repl { break; } - println!("{output}"); + println!("{}", output); } Err(ReadlineError::Interrupted) => { if self.editor.should_exit_on_interrupt() { @@ -75,7 +76,7 @@ impl Repl { break; } Err(err) => { - println!("Error: {err:?}"); + println!("Error: {:?}", err); break; } } @@ -85,6 +86,7 @@ impl Repl { } } +#[allow(clippy::print_stdout)] async fn read_line_and_poll( repl_session: &mut ReplSession, message_handler: &mut RustylineSyncMessageHandler, @@ -152,6 +154,7 @@ async fn read_eval_file( Ok(file.into_text_decoded()?.source) } +#[allow(clippy::print_stdout)] pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> { let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); diff --git a/cli/tools/task.rs b/cli/tools/task.rs index 4d14117d8..63c7f9a94 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -44,7 +44,11 @@ pub async fn execute_script( let task_name = match &task_flags.task { Some(task) => task, None => { - print_available_tasks(&tasks_config, &package_json_scripts); + print_available_tasks( + &mut std::io::stdout(), + &tasks_config, + &package_json_scripts, + )?; return Ok(1); } }; @@ -145,8 +149,14 @@ pub async fn execute_script( Ok(0) } else { - eprintln!("Task not found: {task_name}"); - print_available_tasks(&tasks_config, &package_json_scripts); + log::error!("Task not found: {task_name}"); + if log::log_enabled!(log::Level::Error) { + print_available_tasks( + &mut std::io::stderr(), + &tasks_config, + &package_json_scripts, + )?; + } Ok(1) } } @@ -239,48 +249,58 @@ fn collect_env_vars() -> HashMap<String, String> { } fn print_available_tasks( - // order can be important, so these use an index map + writer: &mut dyn std::io::Write, tasks_config: &IndexMap<String, deno_config::Task>, package_json_scripts: &IndexMap<String, String>, -) { - eprintln!("{}", colors::green("Available tasks:")); - - let mut had_task = false; - for (is_deno, (key, task)) in tasks_config - .iter() - .map(|(k, t)| (true, (k, t.clone()))) - .chain( - package_json_scripts - .iter() - .filter(|(key, _)| !tasks_config.contains_key(*key)) - .map(|(k, v)| (false, (k, deno_config::Task::Definition(v.clone())))), - ) - { - eprintln!( - "- {}{}", - colors::cyan(key), - if is_deno { - "".to_string() - } else { - format!(" {}", colors::italic_gray("(package.json)")) - } - ); - let definition = match &task { - deno_config::Task::Definition(definition) => definition, - deno_config::Task::Commented { definition, .. } => definition, - }; - if let deno_config::Task::Commented { comments, .. } = &task { - let slash_slash = colors::italic_gray("//"); - for comment in comments { - eprintln!(" {slash_slash} {}", colors::italic_gray(comment)); +) -> Result<(), std::io::Error> { + writeln!(writer, "{}", colors::green("Available tasks:"))?; + + if tasks_config.is_empty() && package_json_scripts.is_empty() { + writeln!( + writer, + " {}", + colors::red("No tasks found in configuration file") + )?; + } else { + for (is_deno, (key, task)) in tasks_config + .iter() + .map(|(k, t)| (true, (k, t.clone()))) + .chain( + package_json_scripts + .iter() + .filter(|(key, _)| !tasks_config.contains_key(*key)) + .map(|(k, v)| (false, (k, deno_config::Task::Definition(v.clone())))), + ) + { + writeln!( + writer, + "- {}{}", + colors::cyan(key), + if is_deno { + "".to_string() + } else { + format!(" {}", colors::italic_gray("(package.json)")) + } + )?; + let definition = match &task { + deno_config::Task::Definition(definition) => definition, + deno_config::Task::Commented { definition, .. } => definition, + }; + if let deno_config::Task::Commented { comments, .. } = &task { + let slash_slash = colors::italic_gray("//"); + for comment in comments { + writeln!( + writer, + " {slash_slash} {}", + colors::italic_gray(comment) + )?; + } } + writeln!(writer, " {definition}")?; } - eprintln!(" {definition}"); - had_task = true; - } - if !had_task { - eprintln!(" {}", colors::red("No tasks found in configuration file")); } + + Ok(()) } struct NpxCommand; diff --git a/cli/tools/test/channel.rs b/cli/tools/test/channel.rs index 780a17de6..a8ce7a955 100644 --- a/cli/tools/test/channel.rs +++ b/cli/tools/test/channel.rs @@ -442,6 +442,8 @@ impl TestEventSender { } } +#[allow(clippy::print_stdout)] +#[allow(clippy::print_stderr)] #[cfg(test)] mod tests { use super::*; diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 94541cf06..94d4caee0 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1518,6 +1518,8 @@ pub async fn report_tests( &tests, &test_steps, ); + + #[allow(clippy::print_stderr)] if let Err(err) = reporter.flush_report(&elapsed, &tests, &test_steps) { eprint!("Test reporter failed to flush: {}", err) } diff --git a/cli/tools/test/reporters/dot.rs b/cli/tools/test/reporters/dot.rs index d2e529a9c..854ef9666 100644 --- a/cli/tools/test/reporters/dot.rs +++ b/cli/tools/test/reporters/dot.rs @@ -11,6 +11,7 @@ pub struct DotTestReporter { summary: TestSummary, } +#[allow(clippy::print_stdout)] impl DotTestReporter { pub fn new(cwd: Url) -> DotTestReporter { let console_width = if let Some(size) = crate::util::console::console_size() @@ -80,6 +81,7 @@ fn fmt_cancelled() -> String { colors::gray("!").to_string() } +#[allow(clippy::print_stdout)] impl TestReporter for DotTestReporter { fn report_register(&mut self, _description: &TestDescription) {} diff --git a/cli/tools/test/reporters/tap.rs b/cli/tools/test/reporters/tap.rs index 0758686f0..6dc690e6b 100644 --- a/cli/tools/test/reporters/tap.rs +++ b/cli/tools/test/reporters/tap.rs @@ -22,6 +22,7 @@ pub struct TapTestReporter { step_results: HashMap<usize, Vec<(TestStepDescription, TestStepResult)>>, } +#[allow(clippy::print_stdout)] impl TapTestReporter { pub fn new(cwd: Url, is_concurrent: bool) -> TapTestReporter { TapTestReporter { @@ -113,6 +114,7 @@ impl TapTestReporter { } } +#[allow(clippy::print_stdout)] impl TestReporter for TapTestReporter { fn report_register(&mut self, _description: &TestDescription) {} diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 6bb4606d3..073ebdc1c 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -274,23 +274,17 @@ pub fn check_for_upgrades( if let Some(upgrade_version) = update_checker.should_prompt() { if log::log_enabled!(log::Level::Info) && std::io::stderr().is_terminal() { if version::is_canary() { - eprint!( - "{} ", - colors::green("A new canary release of Deno is available.") - ); - eprintln!( - "{}", + log::info!( + "{} {}", + colors::green("A new canary release of Deno is available."), colors::italic_gray("Run `deno upgrade --canary` to install it.") ); } else { - eprint!( - "{} {} → {} ", + log::info!( + "{} {} → {} {}", colors::green("A new release of Deno is available:"), colors::cyan(version::deno()), - colors::cyan(&upgrade_version) - ); - eprintln!( - "{}", + colors::cyan(&upgrade_version), colors::italic_gray("Run `deno upgrade` to install it.") ); } diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs index 50ae7c233..247ae49d8 100644 --- a/cli/util/file_watcher.rs +++ b/cli/util/file_watcher.rs @@ -73,6 +73,7 @@ impl DebouncedReceiver { } } +#[allow(clippy::print_stderr)] async fn error_handler<F>(watch_future: F) -> bool where F: Future<Output = Result<(), AnyError>>, @@ -132,8 +133,9 @@ fn create_print_after_restart_fn( clear_screen: bool, ) -> impl Fn() { move || { + #[allow(clippy::print_stderr)] if clear_screen && std::io::stderr().is_terminal() { - eprint!("{CLEAR_SCREEN}"); + eprint!("{}", CLEAR_SCREEN); } info!( "{} File change detected! Restarting!", diff --git a/cli/util/v8.rs b/cli/util/v8.rs index 63bc495d1..a8ab2c3d0 100644 --- a/cli/util/v8.rs +++ b/cli/util/v8.rs @@ -43,6 +43,8 @@ pub fn init_v8_flags( .into_iter() .skip(1) .collect::<Vec<_>>(); + + #[allow(clippy::print_stderr)] if !unrecognized_v8_flags.is_empty() { for f in unrecognized_v8_flags { eprintln!("error: V8 did not recognize flag '{f}'"); diff --git a/cli/worker.rs b/cli/worker.rs index 302c00e10..a05dff4b2 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -868,6 +868,8 @@ fn create_web_worker_callback( }) } +#[allow(clippy::print_stdout)] +#[allow(clippy::print_stderr)] #[cfg(test)] mod tests { use super::*; |