Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clippy for denying print and eprints #3967

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -226,6 +221,8 @@ bare_urls = "warn"
[workspace.lints.clippy]
# clippy allowed by default
dbg_macro = "warn"
print_stdout = "deny"
hansl marked this conversation as resolved.
Show resolved Hide resolved
print_stderr = "deny"

# clippy categories https://doc.rust-lang.org/clippy/
all = { level = "warn", priority = -1 }
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
doc-valid-idents = ['ECMAScript', 'JavaScript', 'SpiderMonkey', 'GitHub']
allow-print-in-tests = true
1 change: 0 additions & 1 deletion core/engine/src/object/builtins/jspromise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions core/engine/src/optimizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions core/engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pub(crate) enum CompletionType {
Yield,
}

#[allow(clippy::print_stdout)]
#[cfg(feature = "trace")]
impl Context {
const COLUMN_WIDTH: usize = 26;
Expand Down
10 changes: 4 additions & 6 deletions core/runtime/src/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand All @@ -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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
Loading