Skip to content

Commit ee7a6b5

Browse files
authored
Move lints to workspace (#4294)
1 parent 56f7dec commit ee7a6b5

File tree

98 files changed

+446
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+446
-325
lines changed

.cargo/config.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
11
[target.'cfg(target_arch = "wasm32")']
22
runner = 'cargo run -p wasm-bindgen-cli --bin wasm-bindgen-test-runner --'
3-
4-
[target.'cfg(all())']
5-
rustflags = [
6-
"-Adead_code",
7-
"-Anon_upper_case_globals",
8-
"-Aunused_doc_comments",
9-
"-Aclippy::large_enum_variant",
10-
"-Aclippy::missing_safety_doc",
11-
"-Aclippy::new_without_default",
12-
"-Aclippy::overly_complex_bool_expr",
13-
"-Aclippy::too_many_arguments",
14-
"-Aclippy::type_complexity",
15-
]

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
- run: rustup update --no-self-update stable && rustup default stable
6363
- run: rustup target add wasm32-unknown-unknown
6464
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-backend -- -D warnings
65+
- run: cargo clippy --no-deps --all-features -p wasm-bindgen -- -D warnings
6566
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli -- -D warnings
6667
- run: cargo clippy --no-deps --all-features -p wasm-bindgen-cli-support -- -D warnings
6768
- run: cargo clippy --no-deps --all-features -p example-tests -- -D warnings
@@ -89,8 +90,8 @@ jobs:
8990
- uses: actions/checkout@v4
9091
- run: rustup update --no-self-update stable && rustup default stable
9192
- run: rustup target add wasm32-unknown-unknown
92-
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys -- -D warnings
93-
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys -- -D warnings
93+
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p js-sys --all-targets -- -D warnings
94+
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p web-sys --all-targets -- -D warnings
9495

9596
# Run `cargo clippy` over crates that support `no_std`
9697
clippy_no_std:
@@ -111,7 +112,7 @@ jobs:
111112
name: Clippy `no_std` with `atomics`
112113
runs-on: ubuntu-latest
113114
env:
114-
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory
115+
RUSTFLAGS: -Ctarget-feature=+atomics,+bulk-memory
115116
steps:
116117
- uses: actions/checkout@v4
117118
- run: rustup default nightly-2024-07-06

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ wasm-bindgen-test-crate-b = { path = 'tests/crates/b' }
7070
[lints.rust]
7171
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(wasm_bindgen_unstable_test_coverage)'] }
7272

73+
[lints.clippy]
74+
large_enum_variant = "allow"
75+
new_without_default = "allow"
76+
overly_complex_bool_expr = "allow"
77+
too_many_arguments = "allow"
78+
type_complexity = "allow"
79+
80+
[workspace.lints.clippy]
81+
large_enum_variant = "allow"
82+
new_without_default = "allow"
83+
overly_complex_bool_expr = "allow"
84+
too_many_arguments = "allow"
85+
type_complexity = "allow"
86+
7387
[workspace]
7488
exclude = ["crates/msrv"]
7589
members = [

crates/backend/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ proc-macro2 = "1.0"
2929
quote = '1.0'
3030
syn = { version = '2.0', features = ['full'] }
3131
wasm-bindgen-shared = { path = "../shared", version = "=0.2.95" }
32+
33+
[lints]
34+
workspace = true

crates/cli-support/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ wasm-bindgen-shared = { path = "../shared", version = '=0.2.95' }
2929
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.95' }
3030
wasm-bindgen-wasm-conventions = { path = '../wasm-conventions', version = '=0.2.95' }
3131
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.95' }
32+
33+
[lints]
34+
workspace = true

crates/cli-support/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,3 @@ where
812812
pairs.sort_by_key(|(k, _)| *k);
813813
pairs.into_iter()
814814
}
815-
816-
/// Like `sorted_iter`, but produces mutable references to the values
817-
fn sorted_iter_mut<K, V>(map: &mut HashMap<K, V>) -> impl Iterator<Item = (&K, &mut V)>
818-
where
819-
K: Ord,
820-
{
821-
let mut pairs = map.iter_mut().collect::<Vec<_>>();
822-
pairs.sort_by_key(|(k, _)| *k);
823-
pairs.into_iter()
824-
}

crates/cli-support/src/wit/nonstandard.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ pub enum AuxImport {
244244
mutable: bool, // whether or not this was a `FnMut` closure
245245
dtor: u32, // table element index of the destructor function
246246
adapter: AdapterId, // the adapter which translates the types for this closure
247+
#[allow(dead_code)]
247248
nargs: usize,
248249
},
249250

crates/cli-support/src/wit/standard.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub enum AdapterKind {
4040
instructions: Vec<InstructionData>,
4141
},
4242
Import {
43+
#[allow(dead_code)]
4344
module: String,
4445
name: String,
4546
kind: AdapterJsImportKind,
@@ -139,10 +140,12 @@ pub enum Instruction {
139140
/// Pops a typed integer (`u8`, `s16`, etc.) and pushes a plain Wasm `i32` or `i64` equivalent.
140141
IntToWasm {
141142
input: AdapterType,
143+
#[allow(dead_code)]
142144
output: walrus::ValType,
143145
},
144146
/// Pops a Wasm `i32` or `i64` and pushes a typed integer (`u8`, `s16`, etc.) equivalent.
145147
WasmToInt {
148+
#[allow(dead_code)]
146149
input: walrus::ValType,
147150
output: AdapterType,
148151
},
@@ -166,6 +169,7 @@ pub enum Instruction {
166169

167170
OptionWasmToStringEnum {
168171
name: String,
172+
#[allow(dead_code)]
169173
hole: u32,
170174
},
171175

@@ -310,6 +314,7 @@ pub enum Instruction {
310314
/// pops ptr/length i32, loads string from cache
311315
CachedStringLoad {
312316
owned: bool,
317+
#[allow(dead_code)]
313318
optional: bool,
314319
mem: walrus::MemoryId,
315320
free: walrus::FunctionId,

crates/cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ rustls-tls = ["ureq/tls"]
5757
# Legacy support
5858
openssl = ["dep:native-tls"]
5959
vendored-openssl = ["openssl", "native-tls/vendored"]
60+
61+
[lints]
62+
workspace = true

crates/externref-xform/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ wasmprinter = "0.214"
2424
wast = "214"
2525
wat = "1.0"
2626

27+
[lints]
28+
workspace = true
29+
2730
[[test]]
2831
harness = false
2932
name = "all"

crates/futures/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ version = "=0.3.72"
3838
futures-channel-preview = { version = "0.3.0-alpha.18" }
3939
futures-lite = { version = "1.11.3", default-features = false }
4040
wasm-bindgen-test = { path = '../test' }
41+
42+
[lints]
43+
workspace = true

crates/js-sys/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ web-sys = { path = "../web-sys", features = ["Headers", "Response", "ResponseIni
3434

3535
[lints.rust]
3636
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(js_sys_unstable_apis)'] }
37+
38+
[lints.clippy]
39+
large_enum_variant = "allow"
40+
new_without_default = "allow"
41+
overly_complex_bool_expr = "allow"
42+
too_many_arguments = "allow"
43+
type_complexity = "allow"

crates/js-sys/tests/wasm/Array.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ macro_rules! js_array {
1313

1414
macro_rules! array {
1515
($($e:expr),*) => ({
16-
let mut __x = Vec::new();
17-
$(__x.push(JsValue::from($e));)*
18-
__x
16+
vec![$(JsValue::from($e)),*]
1917
})
2018
}
2119

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

3937
assert_eq!(
4038
to_rust(
41-
&vec![JsValue::from("a"), JsValue::from("b"), JsValue::from("c"),]
39+
&[JsValue::from("a"), JsValue::from("b"), JsValue::from("c")]
4240
.iter()
4341
.collect()
4442
),
@@ -53,7 +51,7 @@ fn from_iter() {
5351
);
5452

5553
assert_eq!(
56-
to_rust(&vec![array.clone(),].iter().collect()),
54+
to_rust(&[array.clone()].iter().collect()),
5755
vec![JsValue::from(array)],
5856
);
5957

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

7674
assert_eq!(
77-
to_rust(&Array::from_iter(v.into_iter().map(|s| JsValue::from(s)))),
75+
to_rust(&Array::from_iter(v.into_iter().map(JsValue::from))),
7876
vec!["a", "b", "c"],
7977
);
8078
}
@@ -290,6 +288,7 @@ fn sort() {
290288
}
291289

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

559558
#[wasm_bindgen_test]
@@ -567,7 +566,7 @@ fn for_each() {
567566
res
568567
}
569568

570-
assert_eq!(sum_indices_of_evens(&js_array![2, 4, 6, 8]), 0 + 1 + 2 + 3);
569+
assert_eq!(sum_indices_of_evens(&js_array![2, 4, 6, 8]), 1 + 2 + 3);
571570
assert_eq!(sum_indices_of_evens(&js_array![1, 3, 5, 7]), 0);
572571
assert_eq!(sum_indices_of_evens(&js_array![3, 5, 7, 10]), 3);
573572
}
@@ -578,7 +577,7 @@ fn set_length() {
578577
array.set_length(3);
579578
assert_eq!(
580579
array.iter().collect::<Vec<_>>(),
581-
[1.0, 2.0, 3.0].map(|x| JsValue::from_f64(x))
580+
[1.0, 2.0, 3.0].map(JsValue::from_f64)
582581
);
583582

584583
array.set_length(7);
@@ -587,7 +586,7 @@ fn set_length() {
587586
[1.0, 2.0, 3.0]
588587
.iter()
589588
.copied()
590-
.map(|x| JsValue::from_f64(x))
589+
.map(JsValue::from_f64)
591590
.chain([JsValue::UNDEFINED; 4])
592591
.collect::<Vec<_>>()
593592
);
@@ -620,8 +619,7 @@ fn test_array_view_mut_raw<ElemT: std::cmp::PartialEq + std::fmt::Debug, ArrT>(
620619
let start: u8 = 10;
621620
let len: usize = 32;
622621
let end: u8 = start + len as u8;
623-
let mut buffer: Vec<ElemT> = Vec::new();
624-
buffer.reserve(len);
622+
let mut buffer: Vec<ElemT> = Vec::with_capacity(len);
625623
unsafe {
626624
let array: ArrT = sut(buffer.as_mut_ptr(), len);
627625
populate_array(

crates/js-sys/tests/wasm/Boolean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use wasm_bindgen_test::*;
66
#[allow(deprecated)]
77
#[wasm_bindgen_test]
88
fn new_undefined() {
9-
assert_eq!(Boolean::new(&JsValue::undefined()).value_of(), false);
9+
assert!(!Boolean::new(&JsValue::undefined()).value_of());
1010
}
1111

1212
#[allow(deprecated)]
1313
#[wasm_bindgen_test]
1414
fn new_truly() {
15-
assert_eq!(Boolean::new(&JsValue::from("foo")).value_of(), true);
15+
assert!(Boolean::new(&JsValue::from("foo")).value_of());
1616
}
1717

1818
#[allow(deprecated)]

crates/js-sys/tests/wasm/Intl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ fn relative_time_format() {
118118
let opts = Object::new();
119119

120120
let c = Intl::RelativeTimeFormat::new(&locales, &opts);
121-
assert!(c.format(1_f64.into(), &"seconds").is_string());
121+
assert!(c.format(1_f64, "seconds").is_string());
122122
assert!(c
123-
.format_to_parts(1_f64.into(), &"seconds")
123+
.format_to_parts(1_f64, "seconds")
124124
.is_instance_of::<Array>());
125125
assert!(c.resolved_options().is_instance_of::<Object>());
126126

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

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

0 commit comments

Comments
 (0)