Browse Source

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
pull/3969/head
Hans Larsen 3 months ago committed by GitHub
parent
commit
1c1d820e0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      Cargo.toml
  2. 1
      cli/src/main.rs
  3. 1
      clippy.toml
  4. 1
      core/engine/src/object/builtins/jspromise.rs
  5. 2
      core/engine/src/optimizer/mod.rs
  6. 1
      core/engine/src/vm/mod.rs
  7. 10
      core/runtime/src/console/mod.rs
  8. 4
      tests/tester/src/main.rs

7
Cargo.toml

@ -3,20 +3,15 @@ resolver = "2"
members = [
# CORE
"core/*",
# FFI
"ffi/*",
# TESTS
"tests/*",
# TOOLS
"tools/*",
# OTHERS
"examples",
"cli",
# TOOLS
"tools/*",
]
@ -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 }

1
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;

1
clippy.toml

@ -1 +1,2 @@
doc-valid-idents = ['ECMAScript', 'JavaScript', 'SpiderMonkey', 'GitHub']
allow-print-in-tests = true

1
core/engine/src/object/builtins/jspromise.rs

@ -1102,7 +1102,6 @@ impl JsPromise {
/// ```
pub fn await_blocking(&self, context: &mut Context) -> Result<JsValue, JsValue> {
loop {
eprintln!("await_blocking: {:?}", self.state());
match self.state() {
PromiseState::Pending => {
context.run_jobs();

2
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()

1
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;

10
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)
}
}

4
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::{

Loading…
Cancel
Save