diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3ca1d3e80..e404507d1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -156,6 +156,8 @@ jobs: - run: ./scripts/wasm_bindgen_check.sh --skip-setup + - run: ./scripts/clippy_wasm.sh + - name: Cranky wasm32 uses: actions-rs/cargo@v1 with: diff --git a/clippy.toml b/clippy.toml index f09ee2776..31bbadb86 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,10 @@ -doc-valid-idents = ["AccessKit", ".."] +# There is also a scripts/clippy_wasm/clippy.toml which forbids some mthods that are not available in wasm. + +msrv = "1.65" + +# Allow-list of words for markdown in dosctrings https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown +doc-valid-idents = [ + # You must also update the same list in the root `clippy.toml`! + "AccessKit", + "..", +] diff --git a/scripts/clippy_wasm.sh b/scripts/clippy_wasm.sh new file mode 100755 index 000000000..b4a1e3e6e --- /dev/null +++ b/scripts/clippy_wasm.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# This scripts run clippy on the wasm32-unknown-unknown target, +# using a special clippy.toml config file which forbids a few more things. + +set -eu +script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$script_path/.." +set -x + +# Use scripts/clippy_wasm/clippy.toml +export CLIPPY_CONF_DIR="scripts/clippy_wasm" + +cargo cranky --all-features --target wasm32-unknown-unknown --target-dir target_wasm -p egui_demo_app --lib -- --deny warnings diff --git a/scripts/clippy_wasm/clippy.toml b/scripts/clippy_wasm/clippy.toml new file mode 100644 index 000000000..e2ec8be96 --- /dev/null +++ b/scripts/clippy_wasm/clippy.toml @@ -0,0 +1,29 @@ +# This is used by `scripts/clippy_wasm.sh` so we can forbid some methods that are not available in wasm. +# +# We cannot forbid all these methods in the main `clippy.toml` because of +# https://github.com/rust-lang/rust-clippy/issues/10406 + +msrv = "1.65" + +# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods +disallowed-methods = [ + "std::time::Instant::now", # use `instant` crate instead for wasm/web compatibility + "std::time::Duration::elapsed", # use `instant` crate instead for wasm/web compatibility + "std::time::SystemTime::now", # use `instant` or `time` crates instead for wasm/web compatibility + + # Cannot spawn threads on wasm: + "std::thread::spawn", +] + +# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types +disallowed-types = [ + # Cannot spawn threads on wasm: + "std::thread::Builder", +] + +# Allow-list of words for markdown in dosctrings https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown +doc-valid-idents = [ + # You must also update the same list in the root `clippy.toml`! + "AccessKit", + "..", +]