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/tools/registry | |
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/tools/registry')
-rw-r--r-- | cli/tools/registry/diagnostics.rs | 18 | ||||
-rw-r--r-- | cli/tools/registry/mod.rs | 44 |
2 files changed, 34 insertions, 28 deletions
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 |