From 5ebe200bb686f27f7ded786b046e55ff47cd8dc0 Mon Sep 17 00:00:00 2001 From: torrybr <16907963+torrybr@users.noreply.github.com> Date: Thu, 11 Jul 2024 03:47:03 -0400 Subject: [PATCH] ci: Improve and run clippy-wasm command Lint more crates with it and enable more features. Also only allow web-time types. --- .github/workflows/ci.yml | 6 ++++++ .wasm/.clippy.toml | 25 +++++++++++++++++++++++++ crates/ruma/Cargo.toml | 15 +++++++++------ xtask/src/ci.rs | 12 +++++------- 4 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 .wasm/.clippy.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 652199ce..3d489c40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -181,6 +181,11 @@ jobs: cmd: clippy-all components: clippy + - name: Clippy WASM + cmd: clippy-wasm + targets: wasm32-unknown-unknown + components: clippy + steps: - name: Checkout repo uses: actions/checkout@v4 @@ -190,6 +195,7 @@ jobs: with: toolchain: ${{ env.NIGHTLY }} components: ${{ matrix.components }} + targets: ${{ matrix.targets }} - uses: Swatinem/rust-cache@v2 diff --git a/.wasm/.clippy.toml b/.wasm/.clippy.toml new file mode 100644 index 00000000..f31de1d1 --- /dev/null +++ b/.wasm/.clippy.toml @@ -0,0 +1,25 @@ +avoid-breaking-exported-api = false +disallowed-methods = [ + # https://github.com/serde-rs/json/issues/160 + "serde_json::from_reader", +] +disallowed-types = [ + "std::collections::HashMap", + "std::collections::HashSet", + { path = "std::time::UNIX_EPOCH", reason = "Use web-time to return a UNIX_EPOCH that works under WASM" }, + { path = "std::time::SystemTime", reason = "Use web-time to return a SystemTime that works under WASM" }, + { path = "std::time::Instant", reason = "Use web-time to return an Instant that works under WASM" }, +] +enforced-import-renames = [ + { path = "serde_json::from_slice", rename = "from_json_slice" }, + { path = "serde_json::from_str", rename = "from_json_str" }, + { path = "serde_json::from_value", rename = "from_json_value" }, + { path = "serde_json::to_value", rename = "to_json_value" }, + { path = "serde_json::value::to_raw_value", rename = "to_raw_json_value" }, + { path = "serde_json::value::RawValue", rename = "RawJsonValue" }, + { path = "serde_json::Value", rename = "JsonValue" }, +] +standard-macro-braces = [ + { name = "quote", brace = "{" }, + { name = "quote::quote", brace = "{" }, +] diff --git a/crates/ruma/Cargo.toml b/crates/ruma/Cargo.toml index b3fa0af7..bfb40d56 100644 --- a/crates/ruma/Cargo.toml +++ b/crates/ruma/Cargo.toml @@ -235,11 +235,8 @@ unstable-unspecified = [ "ruma-push-gateway-api?/unstable-unspecified", ] -# Private feature, only used in test / benchmarking code -__ci = [ - "full", - "compat-upload-signatures", - "unstable-unspecified", +# Private features, only used in test / benchmarking code +__unstable-mscs = [ "unstable-msc1767", "unstable-msc2409", "unstable-msc2448", @@ -281,7 +278,13 @@ __ci = [ "unstable-msc4108", "unstable-msc4121", "unstable-msc4125", - "unstable-msc4140" + "unstable-msc4140", +] +__ci = [ + "full", + "compat-upload-signatures", + "__unstable-mscs", + "unstable-unspecified", ] [dependencies] diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 0ff57663..058c563d 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -60,7 +60,7 @@ pub enum CiCmd { NightlyAll, /// Lint default features with clippy (nightly) ClippyDefault, - /// Lint ruma-common with clippy on a wasm target (nightly) + /// Lint client features with clippy on a wasm target (nightly) ClippyWasm, /// Lint almost all features with clippy (nightly) ClippyAll, @@ -289,17 +289,15 @@ impl CiTask { .map_err(Into::into) } - /// Lint ruma-common with clippy with the nightly version and wasm target. - /// - /// ruma-common is currently the only crate with wasm-specific code. If that changes, this - /// method should be updated. + /// Lint ruma with clippy with the nightly version and wasm target. fn clippy_wasm(&self) -> Result<()> { cmd!( " - rustup run {NIGHTLY} cargo clippy --target wasm32-unknown-unknown - -p ruma-common --features api,js,rand + rustup run {NIGHTLY} cargo clippy --target wasm32-unknown-unknown -p ruma --features + __unstable-mscs,api,canonical-json,client-api,events,html-matrix,identity-service-api,js,markdown,rand,signatures,unstable-unspecified -- -D warnings " ) + .env("CLIPPY_CONF_DIR", ".wasm") .run() .map_err(Into::into) }