Skip to content

Commit

Permalink
Clippy: Fixes and CI for examples and tests (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslihotzki authored May 21, 2023
1 parent 85f72c9 commit d21495b
Show file tree
Hide file tree
Showing 70 changed files with 213 additions and 213 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ jobs:
- run: cargo clippy --no-deps --all-features -p webidl-tests -- -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 -- -D warnings
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown --tests -- -D warnings
- run: cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -p wasm-bindgen-benchmark -- -D warnings
- run: for i in examples/*/; do cd "$i"; cargo clippy --no-deps --all-features --target wasm32-unknown-unknown -- -D warnings || exit 1; cd ../..; done

test_wasm_bindgen:
name: "Run wasm-bindgen crate tests (unix)"
Expand Down
1 change: 1 addition & 0 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "wasm-bindgen-benchmark"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
rust-version = "1.56"

[dependencies]
wasm-bindgen = "0.2.43"
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn fibonacci(n: i32) -> i32 {
unsafe {
FIB_HIGH = (a >> 32) as i32;
}
return a as i32;
a as i32
}

#[wasm_bindgen]
Expand All @@ -68,16 +68,16 @@ pub fn fibonacci_high() -> i32 {
}

#[wasm_bindgen]
pub fn call_foo_bar_final_n_times(n: usize, foo: &Foo) {
pub fn call_foo_bar_final_n_times(n: usize, js_foo: &Foo) {
for _ in 0..n {
foo.bar_final();
js_foo.bar_final();
}
}

#[wasm_bindgen]
pub fn call_foo_bar_structural_n_times(n: usize, foo: &Foo) {
pub fn call_foo_bar_structural_n_times(n: usize, js_foo: &Foo) {
for _ in 0..n {
foo.bar_structural();
js_foo.bar_structural();
}
}

Expand Down
1 change: 1 addition & 0 deletions examples/add/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "add"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/canvas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "canvas"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/char/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "char"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
9 changes: 1 addition & 8 deletions examples/char/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ pub struct Counter {

#[wasm_bindgen]
impl Counter {
pub fn default() -> Counter {
log("Counter::default");
Self::new('a', 0)
}
pub fn new(key: char, count: i32) -> Counter {
log(&format!("Counter::new({}, {})", key, count));
Counter {
key: key,
count: count,
}
Counter { key, count }
}

pub fn key(&self) -> char {
Expand Down
1 change: 1 addition & 0 deletions examples/closures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "closures"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/console_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "console_log"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/deno/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "deno"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/dom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "dom"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/duck-typed-interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "rust-duck-typed-interfaces"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "fetch"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/guide-supported-types-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "guide-supported-types-examples"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 1 addition & 1 deletion examples/guide-supported-types-examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused_variables, dead_code)]
#![allow(unused_variables, dead_code, clippy::boxed_local)]

pub mod bool;
pub mod boxed_js_value_slice;
Expand Down
1 change: 1 addition & 0 deletions examples/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "hello_world"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/julia_set/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "julia_set"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions examples/julia_set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn draw(
) -> Result<(), JsValue> {
// The real workhorse of this algorithm, generating pixel data
let c = Complex { real, imaginary };
let mut data = get_julia_set(width, height, c);
let data = ImageData::new_with_u8_clamped_array_and_sh(Clamped(&mut data), width, height)?;
let data = get_julia_set(width, height, c);
let data = ImageData::new_with_u8_clamped_array_and_sh(Clamped(&data), width, height)?;
ctx.put_image_data(&data, 0.0, 0.0)
}

Expand Down
1 change: 1 addition & 0 deletions examples/paint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "wasm-bindgen-paint"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 0 additions & 2 deletions examples/paint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ fn start() -> Result<(), JsValue> {
closure.forget();
}
{
let context = context.clone();
let pressed = pressed.clone();
let closure = Closure::<dyn FnMut(_)>::new(move |event: web_sys::MouseEvent| {
pressed.set(false);
context.line_to(event.offset_x() as f64, event.offset_y() as f64);
Expand Down
1 change: 1 addition & 0 deletions examples/performance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "performance"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/raytrace-parallel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "raytrace-parallel"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
5 changes: 4 additions & 1 deletion examples/raytrace-parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ impl Scene {
// `pool`.
let thread_pool = rayon::ThreadPoolBuilder::new()
.num_threads(concurrency)
.spawn_handler(|thread| Ok(pool.run(|| thread.run()).unwrap()))
.spawn_handler(|thread| {
pool.run(|| thread.run()).unwrap();
Ok(())
})
.build()
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions examples/request-animation-frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "request-animation-frame"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/synchronous-instantiation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "synchronous-instantiation"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
1 change: 1 addition & 0 deletions examples/todomvc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "todomvc"
version = "0.1.0"
authors = ["The wasm-bindgen Developers"]
edition = "2018"
rust-version = "1.56"

[lib]
crate-type = ["cdylib"]
Expand Down
17 changes: 7 additions & 10 deletions examples/todomvc/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Controller {
id: id.clone(),
title: title.clone(),
});
self.add_message(ViewMessage::EditItemDone(id.to_string(), title.to_string()));
self.add_message(ViewMessage::EditItemDone(id.to_string(), title));
} else {
self.remove_item(&id);
}
Expand All @@ -104,8 +104,7 @@ impl Controller {
if let Some(data) = self.store.find(ItemQuery::Id { id: id.clone() }) {
if let Some(todo) = data.get(0) {
let title = todo.title.to_string();
let citem = id.to_string();
message = Some(ViewMessage::EditItemDone(citem, title));
message = Some(ViewMessage::EditItemDone(id, title));
}
}
if let Some(message) = message {
Expand Down Expand Up @@ -133,18 +132,16 @@ impl Controller {
id: id.clone(),
completed,
});
let tid = id.to_string();
let tid = id;
self.add_message(ViewMessage::SetItemComplete(tid, completed));
}

/// Set all items to complete or active.
fn toggle_all(&mut self, completed: bool) {
let mut vals = Vec::new();
self.store.find(ItemQuery::EmptyItemQuery).map(|data| {
for item in data.iter() {
vals.push(item.id.clone());
}
});
if let Some(data) = self.store.find(ItemQuery::EmptyItemQuery) {
vals.extend(data.iter().map(|item| item.id.clone()));
}
for id in vals.iter() {
self.toggle_completed(id.to_string(), completed);
}
Expand All @@ -155,7 +152,7 @@ impl Controller {
fn _filter(&mut self, force: bool) {
let route = &self.active_route;

if force || self.last_active_route != "" || &self.last_active_route != route {
if force || !self.last_active_route.is_empty() || &self.last_active_route != route {
let query = match route.as_str() {
"completed" => ItemQuery::Completed { completed: true },
"active" => ItemQuery::Completed { completed: false },
Expand Down
31 changes: 10 additions & 21 deletions examples/todomvc/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,21 @@ impl From<web_sys::EventTarget> for Element {

impl From<Element> for Option<web_sys::Node> {
fn from(obj: Element) -> Option<web_sys::Node> {
if let Some(el) = obj.el {
Some(el.into())
} else {
None
}
obj.el.map(Into::into)
}
}

impl From<Element> for Option<EventTarget> {
fn from(obj: Element) -> Option<EventTarget> {
if let Some(el) = obj.el {
Some(el.into())
} else {
None
}
obj.el.map(Into::into)
}
}

impl Element {
// Create an element from a tag name
pub fn create_element(tag: &str) -> Option<Element> {
if let Some(el) = web_sys::window()?.document()?.create_element(tag).ok() {
Some(el.into())
} else {
None
}
let el = web_sys::window()?.document()?.create_element(tag).ok()?;
Some(el.into())
}

pub fn qs(selector: &str) -> Option<Element> {
Expand Down Expand Up @@ -81,7 +70,7 @@ impl Element {
mut handler: T,
use_capture: bool,
) where
T: 'static + FnMut(web_sys::Event) -> (),
T: 'static + FnMut(web_sys::Event),
{
let el = match self.el.take() {
Some(e) => e,
Expand Down Expand Up @@ -154,7 +143,7 @@ impl Element {
pub fn set_text_content(&mut self, value: &str) {
if let Some(el) = self.el.as_ref() {
if let Some(node) = &el.dyn_ref::<web_sys::Node>() {
node.set_text_content(Some(&value));
node.set_text_content(Some(value));
}
}
}
Expand Down Expand Up @@ -204,14 +193,14 @@ impl Element {
/// ```
pub fn class_list_remove(&mut self, value: &str) {
if let Some(el) = self.el.take() {
el.class_list().remove_1(&value).unwrap();
el.class_list().remove_1(value).unwrap();
self.el = Some(el);
}
}

pub fn class_list_add(&mut self, value: &str) {
if let Some(el) = self.el.take() {
el.class_list().add_1(&value).unwrap();
el.class_list().add_1(value).unwrap();
self.el = Some(el);
}
}
Expand All @@ -233,7 +222,7 @@ impl Element {
/// Sets the whole class value for `self.el`
pub fn set_class_name(&mut self, class_name: &str) {
if let Some(el) = self.el.take() {
el.set_class_name(&class_name);
el.set_class_name(class_name);
self.el = Some(el);
}
}
Expand Down Expand Up @@ -307,7 +296,7 @@ impl Element {
pub fn set_value(&mut self, value: &str) {
if let Some(el) = self.el.take() {
if let Some(el) = wasm_bindgen::JsCast::dyn_ref::<web_sys::HtmlInputElement>(&el) {
el.set_value(&value);
el.set_value(value);
}
self.el = Some(el);
}
Expand Down
Loading

0 comments on commit d21495b

Please sign in to comment.