From 1c1d820e0e2ea061d70e2f47e9a6f7aaa5b9c1c1 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Wed, 21 Aug 2024 11:52:25 -0700 Subject: [PATCH] Add clippy for denying print and eprints (#3967) * Remove leftover eprintln from JsPromise::await_blocking * Add clippy for denying print and eprints And remove usage of println or allow them. * Address comment --- Cargo.toml | 11 ++++------- cli/src/main.rs | 1 + clippy.toml | 1 + core/engine/src/object/builtins/jspromise.rs | 1 - core/engine/src/optimizer/mod.rs | 2 ++ core/engine/src/vm/mod.rs | 1 + core/runtime/src/console/mod.rs | 10 ++++------ tests/tester/src/main.rs | 4 +++- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 95af34c296..b701bfaf5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,27 +3,22 @@ resolver = "2" members = [ # CORE "core/*", - # FFI "ffi/*", - # TESTS "tests/*", - # TOOLS "tools/*", - # OTHERS "examples", "cli", - # TOOLS "tools/*", ] exclude = [ "tests/fuzz", # Does weird things on Windows tests - "tests/src", # Just a hack to have fuzz inside tests + "tests/src", # Just a hack to have fuzz inside tests ] [workspace.package] @@ -73,7 +68,7 @@ serde = "1.0.208" static_assertions = "1.1.0" textwrap = "0.16.0" thin-vec = "0.2.13" -time = {version = "0.3.36", default-features = false, features = ["local-offset", "large-dates", "wasm-bindgen", "parsing", "formatting", "macros"]} +time = { version = "0.3.36", default-features = false, features = ["local-offset", "large-dates", "wasm-bindgen", "parsing", "formatting", "macros"] } tinystr = "0.7.5" log = "0.4.22" simple_logger = "5.0.0" @@ -226,6 +221,8 @@ bare_urls = "warn" [workspace.lints.clippy] # clippy allowed by default dbg_macro = "warn" +print_stdout = "warn" +print_stderr = "warn" # clippy categories https://doc.rust-lang.org/clippy/ all = { level = "warn", priority = -1 } diff --git a/cli/src/main.rs b/cli/src/main.rs index 7408901598..c9dbfbba92 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -5,6 +5,7 @@ html_favicon_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg" )] #![cfg_attr(not(test), deny(clippy::unwrap_used))] +#![allow(clippy::print_stdout, clippy::print_stderr)] mod debug; mod helper; diff --git a/clippy.toml b/clippy.toml index 01610f39cb..272425dad8 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,2 @@ doc-valid-idents = ['ECMAScript', 'JavaScript', 'SpiderMonkey', 'GitHub'] +allow-print-in-tests = true diff --git a/core/engine/src/object/builtins/jspromise.rs b/core/engine/src/object/builtins/jspromise.rs index d8a936e96b..393e34e80a 100644 --- a/core/engine/src/object/builtins/jspromise.rs +++ b/core/engine/src/object/builtins/jspromise.rs @@ -1102,7 +1102,6 @@ impl JsPromise { /// ``` pub fn await_blocking(&self, context: &mut Context) -> Result { loop { - eprintln!("await_blocking: {:?}", self.state()); match self.state() { PromiseState::Pending => { context.run_jobs(); diff --git a/core/engine/src/optimizer/mod.rs b/core/engine/src/optimizer/mod.rs index 77a2716e78..d1bf71ec5d 100644 --- a/core/engine/src/optimizer/mod.rs +++ b/core/engine/src/optimizer/mod.rs @@ -114,6 +114,8 @@ impl<'context> Optimizer<'context> { /// Apply optimizations inplace. pub(crate) fn apply(&mut self, statement_list: &mut StatementList) -> OptimizerStatistics { self.visit_statement_list_mut(statement_list); + + #[allow(clippy::print_stdout)] if self .context .optimizer_options() diff --git a/core/engine/src/vm/mod.rs b/core/engine/src/vm/mod.rs index cf32142d4a..4e17a00121 100644 --- a/core/engine/src/vm/mod.rs +++ b/core/engine/src/vm/mod.rs @@ -277,6 +277,7 @@ pub(crate) enum CompletionType { Yield, } +#[allow(clippy::print_stdout)] #[cfg(feature = "trace")] impl Context { const COLUMN_WIDTH: usize = 26; diff --git a/core/runtime/src/console/mod.rs b/core/runtime/src/console/mod.rs index b4507e3e48..bf4945b91e 100644 --- a/core/runtime/src/console/mod.rs +++ b/core/runtime/src/console/mod.rs @@ -19,11 +19,11 @@ use boa_engine::{ native_function::NativeFunction, object::{JsObject, ObjectInitializer}, value::{JsValue, Numeric}, - Context, JsArgs, JsData, JsResult, JsStr, JsString, + Context, JsArgs, JsData, JsError, JsResult, JsStr, JsString, }; use boa_gc::{Finalize, Trace}; use rustc_hash::FxHashMap; -use std::{cell::RefCell, collections::hash_map::Entry, rc::Rc, time::SystemTime}; +use std::{cell::RefCell, collections::hash_map::Entry, io::Write, rc::Rc, time::SystemTime}; /// A trait that can be used to forward console logs to an implementation. pub trait Logger: Trace + Sized { @@ -64,8 +64,7 @@ impl Logger for DefaultLogger { #[inline] fn log(&self, msg: String, state: &Console) -> JsResult<()> { let indent = 2 * state.groups.len(); - println!("{msg:>indent$}"); - Ok(()) + writeln!(std::io::stdout(), "{msg:>indent$}").map_err(JsError::from_rust) } #[inline] @@ -81,8 +80,7 @@ impl Logger for DefaultLogger { #[inline] fn error(&self, msg: String, state: &Console) -> JsResult<()> { let indent = 2 * state.groups.len(); - eprintln!("{msg:>indent$}"); - Ok(()) + writeln!(std::io::stderr(), "{msg:>indent$}").map_err(JsError::from_rust) } } diff --git a/tests/tester/src/main.rs b/tests/tester/src/main.rs index bc31822e35..bc2b862483 100644 --- a/tests/tester/src/main.rs +++ b/tests/tester/src/main.rs @@ -6,7 +6,9 @@ #![allow( clippy::too_many_lines, clippy::redundant_pub_crate, - clippy::cast_precision_loss + clippy::cast_precision_loss, + clippy::print_stderr, + clippy::print_stdout )] use std::{