Skip to content

Commit

Permalink
Move lints to workspace (#4294)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Nov 28, 2024
1 parent 56f7dec commit ee7a6b5
Show file tree
Hide file tree
Showing 98 changed files with 446 additions and 325 deletions.
13 changes: 0 additions & 13 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
[target.'cfg(target_arch = "wasm32")']
runner = 'cargo run -p wasm-bindgen-cli --bin wasm-bindgen-test-runner --'

[target.'cfg(all())']
rustflags = [
"-Adead_code",
"-Anon_upper_case_globals",
"-Aunused_doc_comments",
"-Aclippy::large_enum_variant",
"-Aclippy::missing_safety_doc",
"-Aclippy::new_without_default",
"-Aclippy::overly_complex_bool_expr",
"-Aclippy::too_many_arguments",
"-Aclippy::type_complexity",
]
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
- run: rustup update --no-self-update stable && rustup default stable
- run: rustup target add wasm32-unknown-unknown
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-backend -- -D warnings
- run: cargo clippy --no-deps --all-features -p wasm-bindgen -- -D warnings
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli -- -D warnings
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli-support -- -D warnings
- run: cargo clippy --no-deps --all-features -p example-tests -- -D warnings
Expand Down Expand Up @@ -89,8 +90,8 @@ jobs:
- uses: actions/checkout@v4
- run: rustup update --no-self-update stable && rustup default stable
- run: rustup target add wasm32-unknown-unknown
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys -- -D warnings
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys -- -D warnings
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys --all-targets -- -D warnings
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys --all-targets -- -D warnings

# Run `cargo clippy` over crates that support `no_std`
clippy_no_std:
Expand All @@ -111,7 +112,7 @@ jobs:
name: Clippy `no_std` with `atomics`
runs-on: ubuntu-latest
env:
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory
RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory
steps:
- uses: actions/checkout@v4
- run: rustup default nightly-2024-07-06
Expand Down
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ wasm-bindgen-test-crate-b = { path = 'tests/crates/b' }
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }

[lints.clippy]
large_enum_variant = "allow"
new_without_default = "allow"
overly_complex_bool_expr = "allow"
too_many_arguments = "allow"
type_complexity = "allow"

[workspace.lints.clippy]
large_enum_variant = "allow"
new_without_default = "allow"
overly_complex_bool_expr = "allow"
too_many_arguments = "allow"
type_complexity = "allow"

[workspace]
exclude = ["crates/msrv"]
members = [
Expand Down
3 changes: 3 additions & 0 deletions crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ proc-macro2 = "1.0"
quote = '1.0'
syn = { version = '2.0', features = ['full'] }
wasm-bindgen-shared = { path = "../shared", version = "=0.2.95" }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ wasm-bindgen-shared = { path = "../shared", version = '=0.2.95' }
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.95' }
wasm-bindgen-wasm-conventions = { path = '../wasm-conventions', version = '=0.2.95' }
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.95' }

[lints]
workspace = true
10 changes: 0 additions & 10 deletions crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,3 @@ where
pairs.sort_by_key(|(k, _)| *k);
pairs.into_iter()
}

/// Like `sorted_iter`, but produces mutable references to the values
fn sorted_iter_mut<K, V>(map: &mut HashMap<K, V>) -> impl Iterator<Item = (&K, &mut V)>
where
K: Ord,
{
let mut pairs = map.iter_mut().collect::<Vec<_>>();
pairs.sort_by_key(|(k, _)| *k);
pairs.into_iter()
}
1 change: 1 addition & 0 deletions crates/cli-support/src/wit/nonstandard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ pub enum AuxImport {
mutable: bool, // whether or not this was a `FnMut` closure
dtor: u32, // table element index of the destructor function
adapter: AdapterId, // the adapter which translates the types for this closure
#[allow(dead_code)]
nargs: usize,
},

Expand Down
5 changes: 5 additions & 0 deletions crates/cli-support/src/wit/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum AdapterKind {
instructions: Vec<InstructionData>,
},
Import {
#[allow(dead_code)]
module: String,
name: String,
kind: AdapterJsImportKind,
Expand Down Expand Up @@ -139,10 +140,12 @@ pub enum Instruction {
/// Pops a typed integer (`u8`, `s16`, etc.) and pushes a plain Wasm `i32` or `i64` equivalent.
IntToWasm {
input: AdapterType,
#[allow(dead_code)]
output: walrus::ValType,
},
/// Pops a Wasm `i32` or `i64` and pushes a typed integer (`u8`, `s16`, etc.) equivalent.
WasmToInt {
#[allow(dead_code)]
input: walrus::ValType,
output: AdapterType,
},
Expand All @@ -166,6 +169,7 @@ pub enum Instruction {

OptionWasmToStringEnum {
name: String,
#[allow(dead_code)]
hole: u32,
},

Expand Down Expand Up @@ -310,6 +314,7 @@ pub enum Instruction {
/// pops ptr/length i32, loads string from cache
CachedStringLoad {
owned: bool,
#[allow(dead_code)]
optional: bool,
mem: walrus::MemoryId,
free: walrus::FunctionId,
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ rustls-tls = ["ureq/tls"]
# Legacy support
openssl = ["dep:native-tls"]
vendored-openssl = ["openssl", "native-tls/vendored"]

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/externref-xform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ wasmprinter = "0.214"
wast = "214"
wat = "1.0"

[lints]
workspace = true

[[test]]
harness = false
name = "all"
3 changes: 3 additions & 0 deletions crates/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ version = "=0.3.72"
futures-channel-preview = { version = "0.3.0-alpha.18" }
futures-lite = { version = "1.11.3", default-features = false }
wasm-bindgen-test = { path = '../test' }

[lints]
workspace = true
7 changes: 7 additions & 0 deletions crates/js-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ web-sys = { path = "../web-sys", features = ["Headers", "Response", "ResponseIni

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(js_sys_unstable_apis)'] }

[lints.clippy]
large_enum_variant = "allow"
new_without_default = "allow"
overly_complex_bool_expr = "allow"
too_many_arguments = "allow"
type_complexity = "allow"
22 changes: 10 additions & 12 deletions crates/js-sys/tests/wasm/Array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ macro_rules! js_array {

macro_rules! array {
($($e:expr),*) => ({
let mut __x = Vec::new();
$(__x.push(JsValue::from($e));)*
__x
vec![$(JsValue::from($e)),*]
})
}

Expand All @@ -38,7 +36,7 @@ fn from_iter() {

assert_eq!(
to_rust(
&vec![JsValue::from("a"), JsValue::from("b"), JsValue::from("c"),]
&[JsValue::from("a"), JsValue::from("b"), JsValue::from("c")]
.iter()
.collect()
),
Expand All @@ -53,7 +51,7 @@ fn from_iter() {
);

assert_eq!(
to_rust(&vec![array.clone(),].iter().collect()),
to_rust(&[array.clone()].iter().collect()),
vec![JsValue::from(array)],
);

Expand All @@ -74,7 +72,7 @@ fn from_iter() {
let v = vec!["a", "b", "c"];

assert_eq!(
to_rust(&Array::from_iter(v.into_iter().map(|s| JsValue::from(s)))),
to_rust(&Array::from_iter(v.into_iter().map(JsValue::from))),
vec!["a", "b", "c"],
);
}
Expand Down Expand Up @@ -290,6 +288,7 @@ fn sort() {
}

#[wasm_bindgen_test]
#[allow(clippy::cmp_owned)]
fn some() {
let array = js_array!["z", 1, "y", 2];
assert!(array.some(&mut |e| e == JsValue::from(2)));
Expand Down Expand Up @@ -553,7 +552,7 @@ fn find_last_index() {
fn to_locale_string() {
let output = js_array![1, "a", Date::new(&"21 Dec 1997 14:12:00 UTC".into())]
.to_locale_string(&"en".into(), &JsValue::undefined());
assert!(String::from(output).len() > 0);
assert!(!String::from(output).is_empty());
}

#[wasm_bindgen_test]
Expand All @@ -567,7 +566,7 @@ fn for_each() {
res
}

assert_eq!(sum_indices_of_evens(&js_array![2, 4, 6, 8]), 0 + 1 + 2 + 3);
assert_eq!(sum_indices_of_evens(&js_array![2, 4, 6, 8]), 1 + 2 + 3);
assert_eq!(sum_indices_of_evens(&js_array![1, 3, 5, 7]), 0);
assert_eq!(sum_indices_of_evens(&js_array![3, 5, 7, 10]), 3);
}
Expand All @@ -578,7 +577,7 @@ fn set_length() {
array.set_length(3);
assert_eq!(
array.iter().collect::<Vec<_>>(),
[1.0, 2.0, 3.0].map(|x| JsValue::from_f64(x))
[1.0, 2.0, 3.0].map(JsValue::from_f64)
);

array.set_length(7);
Expand All @@ -587,7 +586,7 @@ fn set_length() {
[1.0, 2.0, 3.0]
.iter()
.copied()
.map(|x| JsValue::from_f64(x))
.map(JsValue::from_f64)
.chain([JsValue::UNDEFINED; 4])
.collect::<Vec<_>>()
);
Expand Down Expand Up @@ -620,8 +619,7 @@ fn test_array_view_mut_raw<ElemT: std::cmp::PartialEq + std::fmt::Debug, ArrT>(
let start: u8 = 10;
let len: usize = 32;
let end: u8 = start + len as u8;
let mut buffer: Vec<ElemT> = Vec::new();
buffer.reserve(len);
let mut buffer: Vec<ElemT> = Vec::with_capacity(len);
unsafe {
let array: ArrT = sut(buffer.as_mut_ptr(), len);
populate_array(
Expand Down
4 changes: 2 additions & 2 deletions crates/js-sys/tests/wasm/Boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use wasm_bindgen_test::*;
#[allow(deprecated)]
#[wasm_bindgen_test]
fn new_undefined() {
assert_eq!(Boolean::new(&JsValue::undefined()).value_of(), false);
assert!(!Boolean::new(&JsValue::undefined()).value_of());
}

#[allow(deprecated)]
#[wasm_bindgen_test]
fn new_truly() {
assert_eq!(Boolean::new(&JsValue::from("foo")).value_of(), true);
assert!(Boolean::new(&JsValue::from("foo")).value_of());
}

#[allow(deprecated)]
Expand Down
10 changes: 5 additions & 5 deletions crates/js-sys/tests/wasm/Intl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ fn relative_time_format() {
let opts = Object::new();

let c = Intl::RelativeTimeFormat::new(&locales, &opts);
assert!(c.format(1_f64.into(), &"seconds").is_string());
assert!(c.format(1_f64, "seconds").is_string());
assert!(c
.format_to_parts(1_f64.into(), &"seconds")
.format_to_parts(1_f64, "seconds")
.is_instance_of::<Array>());
assert!(c.resolved_options().is_instance_of::<Object>());

assert_eq!(c.format(1_f64.into(), &"seconds"), "in 1 second");
assert_eq!(c.format(1.5.into(), &"seconds"), "in 1.5 seconds");
assert_eq!(c.format((-1.5).into(), &"seconds"), "1.5 seconds ago");
assert_eq!(c.format(1_f64, "seconds"), "in 1 second");
assert_eq!(c.format(1.5, "seconds"), "in 1.5 seconds");
assert_eq!(c.format(-1.5, "seconds"), "1.5 seconds ago");

let a = Intl::RelativeTimeFormat::supported_locales_of(&locales, &opts);
assert!(a.is_instance_of::<Array>());
Expand Down
Loading

0 comments on commit ee7a6b5

Please sign in to comment.