Skip to content

Commit

Permalink
Migrate to workspace lints (#3334)
Browse files Browse the repository at this point in the history
* Migrate to workspace lints

* Fix last warnings
  • Loading branch information
jedel1043 authored Nov 17, 2023
1 parent af1a918 commit 421ff70
Show file tree
Hide file tree
Showing 50 changed files with 253 additions and 670 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ jobs:
with:
key: clippy
- name: Clippy (All features)
run: cargo workspaces exec cargo clippy --all-features --all-targets -- -D warnings
run: cargo workspaces exec cargo clippy --all-features --all-targets
- name: Clippy (No features)
run: cargo workspaces exec cargo clippy --no-default-features --all-targets -- -D warnings
run: cargo workspaces exec cargo clippy --no-default-features --all-targets
- name: Clippy (Intl)
run: cargo clippy -p boa_engine --features intl
- name: Clippy (Annex-B)
run: cargo clippy -p boa_engine --features annex-b
- name: Clippy (Experimental)
run: cargo clippy -p boa_engine --features experimental

docs:
name: Documentation
Expand Down
57 changes: 56 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ members = [
[workspace.package]
edition = "2021"
version = "0.17.0"
rust-version = "1.73.0"
rust-version = "1.74.0"
authors = ["boa-dev"]
repository = "https://github.com/boa-dev/boa"
license = "Unlicense OR MIT"
Expand Down Expand Up @@ -116,3 +116,58 @@ opt-level = 1
lto = "fat"
# Makes sure that all code is compiled together, for LTO
codegen-units = 1

[workspace.lints.rust]
# rustc lint groups https://doc.rust-lang.org/rustc/lints/groups.html
warnings = "warn"
future_incompatible = "warn"
let_underscore = "warn"
nonstandard_style = "warn"
rust_2018_compatibility = "warn"
rust_2018_idioms = "warn"
rust_2021_compatibility = "warn"
unused = "warn"

# rustc allowed-by-default lints https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html
missing_docs = "warn"
macro_use_extern_crate = "warn"
meta_variable_misuse = "warn"
missing_abi = "warn"
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
non_ascii_idents = "warn"
noop_method_call = "warn"
single_use_lifetimes = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_crate_dependencies = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"
variant_size_differences = "warn"

[workspace.lints.rustdoc]
# rustdoc lints https://doc.rust-lang.org/rustdoc/lints.html
broken_intra_doc_links = "warn"
private_intra_doc_links = "warn"
missing_crate_level_docs = "warn"
private_doc_tests = "warn"
invalid_codeblock_attributes = "warn"
invalid_rust_codeblocks = "warn"
bare_urls = "warn"

[workspace.lints.clippy]
# clippy allowed by default
dbg_macro = "warn"

# clippy categories https://doc.rust-lang.org/clippy/
all = "warn"
correctness = "warn"
suspicious = "warn"
style = "warn"
complexity = "warn"
perf = "warn"
pedantic = "warn"
3 changes: 3 additions & 0 deletions boa_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ num-bigint.workspace = true
serde = { workspace = true, features = ["derive"], optional = true }
arbitrary = { workspace = true, features = ["derive"], optional = true }
indexmap.workspace = true

[lints]
workspace = true
6 changes: 3 additions & 3 deletions boa_ast/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ mod tests {

/// Checks that we cannot create a position with 0 as the column.
#[test]
#[should_panic]
#[should_panic(expected = "column number cannot be 0")]
fn invalid_position_column() {
Position::new(10, 0);
}

/// Checks that we cannot create a position with 0 as the line.
#[test]
#[should_panic]
#[should_panic(expected = "line number cannot be 0")]
fn invalid_position_line() {
Position::new(0, 10);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ mod tests {

/// Checks that we cannot create an invalid span.
#[test]
#[should_panic]
#[should_panic(expected = "a span cannot start after its end")]
fn invalid_span() {
let a = Position::new(10, 30);
let b = Position::new(10, 50);
Expand Down
3 changes: 3 additions & 0 deletions boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jemallocator.workspace = true
name = "boa"
doc = false
path = "src/main.rs"

[lints]
workspace = true
57 changes: 2 additions & 55 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,6 @@
html_favicon_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo.svg"
)]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
#![warn(
// rustc lint groups https://doc.rust-lang.org/rustc/lints/groups.html
warnings,
future_incompatible,
let_underscore,
nonstandard_style,
rust_2018_compatibility,
rust_2018_idioms,
rust_2021_compatibility,
unused,
// rustc allowed-by-default lints https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html
missing_docs,
macro_use_extern_crate,
meta_variable_misuse,
missing_abi,
missing_copy_implementations,
missing_debug_implementations,
non_ascii_idents,
noop_method_call,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unsafe_op_in_unsafe_fn,
unused_crate_dependencies,
unused_import_braces,
unused_lifetimes,
unused_qualifications,
unused_tuple_struct_fields,
variant_size_differences,
// rustdoc lints https://doc.rust-lang.org/rustdoc/lints.html
rustdoc::broken_intra_doc_links,
rustdoc::private_intra_doc_links,
rustdoc::missing_crate_level_docs,
rustdoc::private_doc_tests,
rustdoc::invalid_codeblock_attributes,
rustdoc::invalid_rust_codeblocks,
rustdoc::bare_urls,
// clippy allowed by default
clippy::dbg_macro,
// clippy categories https://doc.rust-lang.org/clippy/
clippy::all,
clippy::correctness,
clippy::suspicious,
clippy::style,
clippy::complexity,
clippy::perf,
clippy::pedantic,
)]

mod debug;
mod helper;
Expand Down Expand Up @@ -305,7 +252,7 @@ fn generate_flowgraph(
fn evaluate_files(
args: &Opt,
context: &mut Context,
loader: Rc<SimpleModuleLoader>,
loader: &SimpleModuleLoader,
) -> Result<(), io::Error> {
for file in &args.files {
let buffer = read(file)?;
Expand Down Expand Up @@ -485,7 +432,7 @@ fn main() -> Result<(), io::Error> {
.save_history(CLI_HISTORY)
.expect("could not save CLI history");
} else {
evaluate_files(&args, &mut context, loader)?;
evaluate_files(&args, &mut context, &loader)?;
}

Ok(())
Expand Down
3 changes: 3 additions & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ bench = false
[[bench]]
name = "full"
harness = false

[lints]
workspace = true
4 changes: 3 additions & 1 deletion boa_engine/benches/full.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_crate_dependencies, missing_docs)]

//! Benchmarks of the whole execution engine in Boa.

use boa_engine::{
Expand All @@ -17,7 +19,7 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
fn create_realm(c: &mut Criterion) {
c.bench_function("Create Realm", move |b| {
let root_shape = RootShape::default();
b.iter(|| Realm::create(&DefaultHooks, &root_shape))
b.iter(|| Realm::create(&DefaultHooks, &root_shape));
});
}

Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl OrdinaryFunction {
&self.realm
}

/// Check if function is [`FunctionKind::Ordinary`].
/// Checks if this function is an ordinary function.
pub(crate) fn is_ordinary(&self) -> bool {
self.code.is_ordinary()
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/intl/locale/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ fn lookup_supported_locales<M: KeyedDataMarker>(
// 3. Return subset.
requested_locales
.iter()
.cloned()
.filter(|loc| best_available_locale(loc.id.clone(), provider).is_some())
.cloned()
.collect()
}

Expand All @@ -517,8 +517,8 @@ fn best_fit_supported_locales<M: KeyedDataMarker>(
) -> Vec<Locale> {
requested_locales
.iter()
.cloned()
.filter(|loc| best_locale_for_provider(loc.id.clone(), provider).is_some())
.cloned()
.collect()
}

Expand Down
97 changes: 50 additions & 47 deletions boa_engine/src/builtins/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,53 +124,6 @@ pub(crate) enum RoundingMode {
HalfEven,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum UnsignedRoundingMode {
Infinity,
Zero,
HalfInfinity,
HalfZero,
HalfEven,
}

impl RoundingMode {
pub(crate) const fn negate(self) -> Self {
use RoundingMode::{
Ceil, Expand, Floor, HalfCeil, HalfEven, HalfExpand, HalfFloor, HalfTrunc, Trunc,
};

match self {
Ceil => Self::Floor,
Floor => Self::Ceil,
HalfCeil => Self::HalfFloor,
HalfFloor => Self::HalfCeil,
Trunc => Self::Trunc,
Expand => Self::Expand,
HalfTrunc => Self::HalfTrunc,
HalfExpand => Self::HalfExpand,
HalfEven => Self::HalfEven,
}
}

pub(crate) const fn get_unsigned_round_mode(self, is_negative: bool) -> UnsignedRoundingMode {
use RoundingMode::{
Ceil, Expand, Floor, HalfCeil, HalfEven, HalfExpand, HalfFloor, HalfTrunc, Trunc,
};

match self {
Ceil if !is_negative => UnsignedRoundingMode::Infinity,
Ceil => UnsignedRoundingMode::Zero,
Floor if !is_negative => UnsignedRoundingMode::Zero,
Floor | Trunc | Expand => UnsignedRoundingMode::Infinity,
HalfCeil if !is_negative => UnsignedRoundingMode::HalfInfinity,
HalfCeil | HalfTrunc => UnsignedRoundingMode::HalfZero,
HalfFloor if !is_negative => UnsignedRoundingMode::HalfZero,
HalfFloor | HalfExpand => UnsignedRoundingMode::HalfInfinity,
HalfEven => UnsignedRoundingMode::HalfEven,
}
}
}

#[derive(Debug)]
pub(crate) struct ParseRoundingModeError;

Expand Down Expand Up @@ -217,3 +170,53 @@ impl fmt::Display for RoundingMode {
.fmt(f)
}
}

#[cfg(feature = "temporal")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum UnsignedRoundingMode {
Infinity,
Zero,
HalfInfinity,
HalfZero,
HalfEven,
}

impl RoundingMode {
#[cfg(feature = "temporal")]
pub(crate) const fn negate(self) -> Self {
use RoundingMode::{
Ceil, Expand, Floor, HalfCeil, HalfEven, HalfExpand, HalfFloor, HalfTrunc, Trunc,
};

match self {
Ceil => Self::Floor,
Floor => Self::Ceil,
HalfCeil => Self::HalfFloor,
HalfFloor => Self::HalfCeil,
Trunc => Self::Trunc,
Expand => Self::Expand,
HalfTrunc => Self::HalfTrunc,
HalfExpand => Self::HalfExpand,
HalfEven => Self::HalfEven,
}
}

#[cfg(feature = "temporal")]
pub(crate) const fn get_unsigned_round_mode(self, is_negative: bool) -> UnsignedRoundingMode {
use RoundingMode::{
Ceil, Expand, Floor, HalfCeil, HalfEven, HalfExpand, HalfFloor, HalfTrunc, Trunc,
};

match self {
Ceil if !is_negative => UnsignedRoundingMode::Infinity,
Ceil => UnsignedRoundingMode::Zero,
Floor if !is_negative => UnsignedRoundingMode::Zero,
Floor | Trunc | Expand => UnsignedRoundingMode::Infinity,
HalfCeil if !is_negative => UnsignedRoundingMode::HalfInfinity,
HalfCeil | HalfTrunc => UnsignedRoundingMode::HalfZero,
HalfFloor if !is_negative => UnsignedRoundingMode::HalfZero,
HalfFloor | HalfExpand => UnsignedRoundingMode::HalfInfinity,
HalfEven => UnsignedRoundingMode::HalfEven,
}
}
}
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/temporal/duration/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ impl DurationRecord {
// 2. If zonedRelativeTo is not present, set zonedRelativeTo to undefined.
let zoned_relative_to = relative_targets.1;
// 3. If precalculatedPlainDateTime is not present, set precalculatedPlainDateTime to undefined.
let _precalc_pdt = relative_targets.2;
let _ = relative_targets.2;

let (frac_days, frac_secs) = match unit {
// 4. If unit is "year", "month", or "week", and plainRelativeTo is undefined, then
Expand Down
1 change: 1 addition & 0 deletions boa_engine/src/builtins/typed_array/element/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(unsafe_op_in_unsafe_fn)]
#![allow(clippy::cast_ptr_alignment)] // Invariants are checked by the caller.
#![allow(unused_tuple_struct_fields)] // Weird false-positive with `boa_macros_tests`

mod atomic;

Expand Down
Loading

0 comments on commit 421ff70

Please sign in to comment.