summaryrefslogtreecommitdiff
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
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.
-rw-r--r--Cargo.lock2
-rw-r--r--bench_util/profiling.rs1
-rw-r--r--cli/args/flags.rs18
-rw-r--r--cli/args/mod.rs9
-rw-r--r--cli/bench/main.rs3
-rw-r--r--cli/file_fetcher.rs2
-rw-r--r--cli/main.rs6
-rw-r--r--cli/mainrt.rs4
-rw-r--r--cli/ops/jupyter.rs4
-rw-r--r--cli/tools/bench/reporters.rs4
-rw-r--r--cli/tools/bundle.rs5
-rw-r--r--cli/tools/coverage/reporter.rs5
-rw-r--r--cli/tools/fmt.rs5
-rw-r--r--cli/tools/info.rs1
-rw-r--r--cli/tools/jupyter/install.rs6
-rw-r--r--cli/tools/jupyter/server.rs73
-rw-r--r--cli/tools/lint/mod.rs20
-rw-r--r--cli/tools/registry/diagnostics.rs18
-rw-r--r--cli/tools/registry/mod.rs44
-rw-r--r--cli/tools/repl/editor.rs2
-rw-r--r--cli/tools/repl/mod.rs7
-rw-r--r--cli/tools/task.rs100
-rw-r--r--cli/tools/test/channel.rs2
-rw-r--r--cli/tools/test/mod.rs2
-rw-r--r--cli/tools/test/reporters/dot.rs2
-rw-r--r--cli/tools/test/reporters/tap.rs2
-rw-r--r--cli/tools/upgrade.rs18
-rw-r--r--cli/util/file_watcher.rs4
-rw-r--r--cli/util/v8.rs2
-rw-r--r--cli/worker.rs2
-rw-r--r--ext/ffi/Cargo.toml1
-rw-r--r--ext/ffi/callback.rs2
-rw-r--r--ext/http/response_body.rs1
-rw-r--r--ext/io/Cargo.toml1
-rw-r--r--ext/io/winpipe.rs4
-rw-r--r--runtime/examples/extension/main.rs3
-rw-r--r--runtime/inspector_server.rs18
-rw-r--r--runtime/permissions/prompter.rs3
-rw-r--r--runtime/snapshot.rs1
-rw-r--r--runtime/tokio_util.rs3
-rw-r--r--runtime/web_worker.rs2
-rw-r--r--runtime/worker.rs3
-rw-r--r--tests/ffi/src/lib.rs2
-rw-r--r--tests/ffi/tests/integration_tests.rs3
-rw-r--r--tests/integration/inspector_tests.rs40
-rw-r--r--tests/integration/mod.rs3
-rw-r--r--tests/napi/src/lib.rs3
-rw-r--r--tests/napi/tests/napi_tests.rs7
-rw-r--r--tests/testdata/inspector/inspector_test.js5
-rw-r--r--tests/util/server/src/lib.rs3
-rw-r--r--tests/util/server/src/test_server.rs3
-rwxr-xr-xtools/lint.js6
52 files changed, 308 insertions, 182 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2c31279a4..dd59fde10 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1453,6 +1453,7 @@ dependencies = [
"dynasmrt",
"libffi",
"libffi-sys",
+ "log",
"serde",
"serde-value",
"serde_json",
@@ -1557,6 +1558,7 @@ dependencies = [
"deno_core",
"filetime",
"fs3",
+ "log",
"once_cell",
"os_pipe",
"rand",
diff --git a/bench_util/profiling.rs b/bench_util/profiling.rs
index 239364988..151a29e59 100644
--- a/bench_util/profiling.rs
+++ b/bench_util/profiling.rs
@@ -39,6 +39,7 @@ macro_rules! bench_or_profile {
};
}
+#[allow(clippy::print_stdout)]
pub fn run_profiles(opts: &TestOpts, tests: Vec<TestDescAndFn>) {
let tests = filter_tests(opts, tests);
// let decs = tests.iter().map(|t| t.desc.clone()).collect();
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::*;
diff --git a/ext/ffi/Cargo.toml b/ext/ffi/Cargo.toml
index 9e6ade702..8af1b2016 100644
--- a/ext/ffi/Cargo.toml
+++ b/ext/ffi/Cargo.toml
@@ -19,6 +19,7 @@ dlopen2.workspace = true
dynasmrt = "1.2.3"
libffi = "=3.2.0"
libffi-sys = "=2.3.0"
+log.workspace = true
serde.workspace = true
serde-value = "0.7"
serde_json = "1.0"
diff --git a/ext/ffi/callback.rs b/ext/ffi/callback.rs
index eeea49c23..55f38c602 100644
--- a/ext/ffi/callback.rs
+++ b/ext/ffi/callback.rs
@@ -176,7 +176,7 @@ unsafe extern "C" fn deno_ffi_callback(
let tc_scope = &mut TryCatch::new(scope);
args.run(tc_scope);
if tc_scope.exception().is_some() {
- eprintln!("Illegal unhandled exception in nonblocking callback.");
+ log::error!("Illegal unhandled exception in nonblocking callback.");
}
});
}
diff --git a/ext/http/response_body.rs b/ext/http/response_body.rs
index 6b033ffe0..fd1203f53 100644
--- a/ext/http/response_body.rs
+++ b/ext/http/response_body.rs
@@ -625,6 +625,7 @@ impl PollFrame for BrotliResponseStream {
}
}
+#[allow(clippy::print_stderr)]
#[cfg(test)]
mod tests {
use super::*;
diff --git a/ext/io/Cargo.toml b/ext/io/Cargo.toml
index 17a967834..70b5c63f8 100644
--- a/ext/io/Cargo.toml
+++ b/ext/io/Cargo.toml
@@ -18,6 +18,7 @@ async-trait.workspace = true
deno_core.workspace = true
filetime.workspace = true
fs3.workspace = true
+log.workspace = true
once_cell.workspace = true
tokio.workspace = true
diff --git a/ext/io/winpipe.rs b/ext/io/winpipe.rs
index f66dec6b6..01d018008 100644
--- a/ext/io/winpipe.rs
+++ b/ext/io/winpipe.rs
@@ -74,7 +74,7 @@ fn create_named_pipe_inner() -> io::Result<(RawHandle, RawHandle)> {
// This should not happen, so we would like to get some better diagnostics here.
// SAFETY: Printing last error for diagnostics
unsafe {
- eprintln!(
+ log::error!(
"*** Unexpected server pipe failure '{pipe_name:?}': {:x}",
GetLastError()
);
@@ -99,7 +99,7 @@ fn create_named_pipe_inner() -> io::Result<(RawHandle, RawHandle)> {
// SAFETY: Getting last error for diagnostics
let error = unsafe { GetLastError() };
// This should not happen, so we would like to get some better diagnostics here.
- eprintln!(
+ log::error!(
"*** Unexpected client pipe failure '{pipe_name:?}': {:x}",
error
);
diff --git a/runtime/examples/extension/main.rs b/runtime/examples/extension/main.rs
index 0026d0de0..0d7c4efb0 100644
--- a/runtime/examples/extension/main.rs
+++ b/runtime/examples/extension/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 std::path::Path;
use std::rc::Rc;
diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs
index 8d93819e9..48d8e0a8f 100644
--- a/runtime/inspector_server.rs
+++ b/runtime/inspector_server.rs
@@ -176,7 +176,7 @@ fn handle_ws_request(
let websocket = match fut.await {
Ok(w) => w,
Err(err) => {
- eprintln!(
+ log::error!(
"Inspector server failed to upgrade to WS connection: {:?}",
err
);
@@ -194,7 +194,7 @@ fn handle_ws_request(
rx: inbound_rx,
};
- eprintln!("Debugger session started.");
+ log::info!("Debugger session started.");
let _ = new_session_tx.unbounded_send(inspector_session_proxy);
pump_websocket_messages(websocket, inbound_tx, outbound_rx).await;
});
@@ -244,13 +244,13 @@ async fn server(
let inspector_map = Rc::clone(&inspector_map_);
let mut register_inspector_handler = pin!(register_inspector_rx
.map(|info| {
- eprintln!(
+ log::info!(
"Debugger listening on {}",
info.get_websocket_debugger_url(&info.host.to_string())
);
- eprintln!("Visit chrome://inspect to connect to the debugger.");
+ log::info!("Visit chrome://inspect to connect to the debugger.");
if info.wait_for_session {
- eprintln!("Deno is waiting for debugger to connect.");
+ log::info!("Deno is waiting for debugger to connect.");
}
if inspector_map.borrow_mut().insert(info.uuid, info).is_some() {
panic!("Inspector UUID already in map");
@@ -277,7 +277,7 @@ async fn server(
let listener = match TcpListener::from_std(listener) {
Ok(l) => l,
Err(err) => {
- eprintln!("Cannot start inspector server: {:?}", err);
+ log::error!("Cannot start inspector server: {:?}", err);
return;
}
};
@@ -293,7 +293,7 @@ async fn server(
match accept_result {
Ok((s, _)) => s,
Err(err) => {
- eprintln!("Failed to accept inspector connection: {:?}", err);
+ log::error!("Failed to accept inspector connection: {:?}", err);
continue;
}
}
@@ -356,7 +356,7 @@ async fn server(
tokio::select! {
result = conn.as_mut() => {
if let Err(err) = result {
- eprintln!("Failed to serve connection: {:?}", err);
+ log::error!("Failed to serve connection: {:?}", err);
}
},
_ = &mut shutdown_rx => {
@@ -409,7 +409,7 @@ async fn pump_websocket_messages(
OpCode::Close => {
// Users don't care if there was an error coming from debugger,
// just about the fact that debugger did disconnect.
- eprintln!("Debugger session ended");
+ log::info!("Debugger session ended");
break 'pump;
}
_ => {
diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs
index 42567b1e9..59a3a2f7b 100644
--- a/runtime/permissions/prompter.rs
+++ b/runtime/permissions/prompter.rs
@@ -280,6 +280,7 @@ impl PermissionPrompter for TtyPrompter {
return PromptResponse::Deny;
};
+ #[allow(clippy::print_stderr)]
if message.len() > MAX_PERMISSION_PROMPT_LENGTH {
eprintln!("❌ Permission prompt length ({} bytes) was larger than the configured maximum length ({} bytes): denying request.", message.len(), MAX_PERMISSION_PROMPT_LENGTH);
eprintln!("❌ WARNING: This may indicate that code is trying to bypass or hide permission check requests.");
@@ -298,6 +299,7 @@ impl PermissionPrompter for TtyPrompter {
// For security reasons we must consume everything in stdin so that previously
// buffered data cannot affect the prompt.
+ #[allow(clippy::print_stderr)]
if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) {
eprintln!("Error clearing stdin for permission prompt. {err:#}");
return PromptResponse::Deny; // don't grant permission if this fails
@@ -336,6 +338,7 @@ impl PermissionPrompter for TtyPrompter {
// Clear stdin each time we loop around in case the user accidentally pasted
// multiple lines or otherwise did something silly to generate a torrent of
// input. This doesn't work on Windows because `clear_stdin` has other side-effects.
+ #[allow(clippy::print_stderr)]
#[cfg(unix)]
if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) {
eprintln!("Error clearing stdin for permission prompt. {err:#}");
diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs
index 2a7d97641..923ea0b75 100644
--- a/runtime/snapshot.rs
+++ b/runtime/snapshot.rs
@@ -296,6 +296,7 @@ pub fn create_runtime_snapshot(
let mut snapshot = std::fs::File::create(snapshot_path).unwrap();
snapshot.write_all(&output.output).unwrap();
+ #[allow(clippy::print_stdout)]
for path in output.files_loaded_during_snapshot {
println!("cargo:rerun-if-changed={}", path.display());
}
diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs
index da6e8b221..0d81f6e23 100644
--- a/runtime/tokio_util.rs
+++ b/runtime/tokio_util.rs
@@ -81,8 +81,9 @@ where
let handle = tokio::runtime::Handle::current();
let runtime_monitor = RuntimeMonitor::new(&handle);
tokio::spawn(async move {
+ #[allow(clippy::print_stderr)]
for interval in runtime_monitor.intervals() {
- println!("{:#?}", interval);
+ eprintln!("{:#?}", interval);
// wait 500ms
tokio::time::sleep(std::time::Duration::from_millis(
metrics_interval,
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index 27fe633ad..0124b12a3 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -805,6 +805,7 @@ impl WebWorker {
// TODO(mmastrac): we don't want to test this w/classic workers because
// WPT triggers a failure here. This is only exposed via --enable-testing-features-do-not-use.
+ #[allow(clippy::print_stderr)]
if self.worker_type == WebWorkerType::Module {
panic!(
"coding error: either js is polling or the worker is terminated"
@@ -878,6 +879,7 @@ impl WebWorker {
}
}
+#[allow(clippy::print_stderr)]
fn print_worker_error(
error: &AnyError,
name: &str,
diff --git a/runtime/worker.rs b/runtime/worker.rs
index ee6b256ff..a5fec16e4 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -279,6 +279,7 @@ pub fn create_op_metrics(
max_len.set(max_len.get().max(decl.name.len()));
let max_len = max_len.clone();
Some(Rc::new(
+ #[allow(clippy::print_stderr)]
move |op: &deno_core::_ops::OpCtx, event, source| {
eprintln!(
"[{: >10.3}] {name:max_len$}: {event:?} {source:?}",
@@ -518,7 +519,7 @@ impl MainWorker {
if !has_notified_of_inspector_disconnect
.swap(true, std::sync::atomic::Ordering::SeqCst)
{
- println!("Program finished. Waiting for inspector to disconnect to exit the process...");
+ log::info!("Program finished. Waiting for inspector to disconnect to exit the process...");
}
});
diff --git a/tests/ffi/src/lib.rs b/tests/ffi/src/lib.rs
index f6ee31eb8..09c2afb3d 100644
--- a/tests/ffi/src/lib.rs
+++ b/tests/ffi/src/lib.rs
@@ -1,5 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
#![allow(clippy::undocumented_unsafe_blocks)]
use std::os::raw::c_void;
diff --git a/tests/ffi/tests/integration_tests.rs b/tests/ffi/tests/integration_tests.rs
index 0ad95254c..d0ac6e104 100644
--- a/tests/ffi/tests/integration_tests.rs
+++ b/tests/ffi/tests/integration_tests.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 pretty_assertions::assert_eq;
use std::process::Command;
use test_util::deno_cmd;
diff --git a/tests/integration/inspector_tests.rs b/tests/integration/inspector_tests.rs
index d18375a83..6a0f9111e 100644
--- a/tests/integration/inspector_tests.rs
+++ b/tests/integration/inspector_tests.rs
@@ -21,6 +21,7 @@ use test_util as util;
use tokio::net::TcpStream;
use tokio::time::timeout;
use url::Url;
+use util::assert_contains;
use util::assert_starts_with;
use util::DenoChild;
use util::TestContextBuilder;
@@ -94,12 +95,18 @@ impl InspectorTester {
F: FnMut(&str) -> bool + 'static,
{
let stdout = child.stdout.take().unwrap();
- let stdout_lines =
- std::io::BufReader::new(stdout).lines().map(|r| r.unwrap());
+ let stdout_lines = std::io::BufReader::new(stdout).lines().map(|r| {
+ let line = r.unwrap();
+ eprintln!("STDOUT: {}", line);
+ line
+ });
let stderr = child.stderr.take().unwrap();
- let mut stderr_lines =
- std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
+ let mut stderr_lines = std::io::BufReader::new(stderr).lines().map(|r| {
+ let line = r.unwrap();
+ eprintln!("STDERR: {}", line);
+ line
+ });
let uri = extract_ws_url_from_stderr(&mut stderr_lines);
@@ -810,7 +817,6 @@ async fn inspector_break_on_first_line_in_test() {
let script = util::testdata_path().join("inspector/inspector_test.js");
let child = util::deno_cmd()
.arg("test")
- .arg("--quiet")
.arg(inspect_flag_with_unique_port("--inspect-brk"))
.arg(script)
.env("NO_COLOR", "1")
@@ -877,10 +883,7 @@ async fn inspector_break_on_first_line_in_test() {
assert_starts_with!(&tester.stdout_line(), "running 1 test from");
let line = tester.stdout_line();
- assert!(
- &line.contains("basic test ... ok"),
- "Missing content: {line}"
- );
+ assert_contains!(line, "basic test ... ok");
tester.child.kill().unwrap();
tester.child.wait().unwrap();
@@ -907,6 +910,7 @@ async fn inspector_with_ts_files() {
let mut tester = InspectorTester::create(child, notification_filter).await;
tester.assert_stderr_for_inspect_brk();
+ assert_eq!(&tester.stderr_line(), "Debugger session started.");
tester
.send_many(&[
@@ -926,19 +930,19 @@ async fn inspector_with_ts_files() {
// receive messages with sources from this test
let script1 = tester.recv().await;
- assert!(script1.contains("testdata/inspector/test.ts"));
+ assert_contains!(script1, "testdata/inspector/test.ts");
let script1_id = {
let v: serde_json::Value = serde_json::from_str(&script1).unwrap();
v["params"]["scriptId"].as_str().unwrap().to_string()
};
let script2 = tester.recv().await;
- assert!(script2.contains("testdata/inspector/foo.ts"));
+ assert_contains!(script2, "testdata/inspector/foo.ts");
let script2_id = {
let v: serde_json::Value = serde_json::from_str(&script2).unwrap();
v["params"]["scriptId"].as_str().unwrap().to_string()
};
let script3 = tester.recv().await;
- assert!(script3.contains("testdata/inspector/bar.js"));
+ assert_contains!(script3, "testdata/inspector/bar.js");
let script3_id = {
let v: serde_json::Value = serde_json::from_str(&script3).unwrap();
v["params"]["scriptId"].as_str().unwrap().to_string()
@@ -996,10 +1000,12 @@ async fn inspector_with_ts_files() {
)
.await;
+ let line = tester.stderr_line();
+ assert_contains!(test_util::strip_ansi_codes(&line), "Check");
assert_eq!(
- &tester.stdout_line(),
- "Program finished. Waiting for inspector to disconnect to exit the process..."
- );
+ &tester.stderr_line(),
+ "Program finished. Waiting for inspector to disconnect to exit the process..."
+ );
tester.child.kill().unwrap();
tester.child.wait().unwrap();
@@ -1194,7 +1200,6 @@ async fn inspector_break_on_first_line_npm_esm() {
.new_command()
.args_vec([
"run",
- "--quiet",
&inspect_flag_with_unique_port("--inspect-brk"),
"npm:@denotest/bin/cli-esm",
"this",
@@ -1262,7 +1267,6 @@ async fn inspector_break_on_first_line_npm_cjs() {
.new_command()
.args_vec([
"run",
- "--quiet",
&inspect_flag_with_unique_port("--inspect-brk"),
"npm:@denotest/bin/cli-cjs",
"this",
@@ -1331,7 +1335,6 @@ async fn inspector_error_with_npm_import() {
.new_command()
.args_vec([
"run",
- "--quiet",
"-A",
&inspect_flag_with_unique_port("--inspect-brk"),
&script.to_string_lossy(),
@@ -1394,7 +1397,6 @@ async fn inspector_wait() {
.new_command()
.args_vec([
"run",
- "--quiet",
"-A",
&inspect_flag_with_unique_port("--inspect-wait"),
&script.to_string_lossy(),
diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs
index 30cc9a791..59bf0db37 100644
--- a/tests/integration/mod.rs
+++ b/tests/integration/mod.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
// These files have `_tests.rs` suffix to make it easier to tell which file is
// the test (ex. `lint_tests.rs`) and which is the implementation (ex. `lint.rs`)
// when both are open, especially for two tabs in VS Code
diff --git a/tests/napi/src/lib.rs b/tests/napi/src/lib.rs
index 1b9246483..f6fe6e189 100644
--- a/tests/napi/src/lib.rs
+++ b/tests/napi/src/lib.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
#![allow(clippy::all)]
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
#![allow(clippy::undocumented_unsafe_blocks)]
use std::ffi::c_void;
diff --git a/tests/napi/tests/napi_tests.rs b/tests/napi/tests/napi_tests.rs
index 671699651..1c9b1ba94 100644
--- a/tests/napi/tests/napi_tests.rs
+++ b/tests/napi/tests/napi_tests.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 std::process::Command;
use test_util::deno_cmd;
use test_util::deno_config_path;
@@ -80,8 +83,8 @@ fn napi_tests() {
if !output.status.success() {
eprintln!("exit code {:?}", output.status.code());
- println!("stdout {stdout}");
- println!("stderr {stderr}");
+ println!("stdout {}", stdout);
+ println!("stderr {}", stderr);
}
assert!(output.status.success());
}
diff --git a/tests/testdata/inspector/inspector_test.js b/tests/testdata/inspector/inspector_test.js
index 86cd48854..e1ac7b635 100644
--- a/tests/testdata/inspector/inspector_test.js
+++ b/tests/testdata/inspector/inspector_test.js
@@ -1,3 +1,6 @@
Deno.test("basic test", () => {
- console.log("test has finished running");
+ const value = 1 + 1;
+ if (value !== 2) {
+ throw new Error("failed");
+ }
});
diff --git a/tests/util/server/src/lib.rs b/tests/util/server/src/lib.rs
index ec9154af2..ee5348049 100644
--- a/tests/util/server/src/lib.rs
+++ b/tests/util/server/src/lib.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 std::collections::HashMap;
use std::env;
use std::io::Write;
diff --git a/tests/util/server/src/test_server.rs b/tests/util/server/src/test_server.rs
index 19e33f9f5..3ae3eaa7d 100644
--- a/tests/util/server/src/test_server.rs
+++ b/tests/util/server/src/test_server.rs
@@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+#![allow(clippy::print_stdout)]
+#![allow(clippy::print_stderr)]
+
fn main() {
setup_panic_hook();
test_server::servers::run_all_servers();
diff --git a/tools/lint.js b/tools/lint.js
index 2bb91f3d5..0fe96b049 100755
--- a/tools/lint.js
+++ b/tools/lint.js
@@ -162,6 +162,12 @@ async function clippy() {
"warnings",
"--deny",
"clippy::unused_async",
+ // generally prefer the `log` crate, but ignore
+ // these print_* rules if necessary
+ "--deny",
+ "clippy::print_stderr",
+ "--deny",
+ "clippy::print_stdout",
],
stdout: "inherit",
stderr: "inherit",