ci: Improve and run clippy-wasm command

Lint more crates with it and enable more features. Also only allow web-time types.
This commit is contained in:
torrybr 2024-07-11 03:47:03 -04:00 committed by GitHub
parent 7f562fe67e
commit 5ebe200bb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 13 deletions

View File

@ -181,6 +181,11 @@ jobs:
cmd: clippy-all cmd: clippy-all
components: clippy components: clippy
- name: Clippy WASM
cmd: clippy-wasm
targets: wasm32-unknown-unknown
components: clippy
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -190,6 +195,7 @@ jobs:
with: with:
toolchain: ${{ env.NIGHTLY }} toolchain: ${{ env.NIGHTLY }}
components: ${{ matrix.components }} components: ${{ matrix.components }}
targets: ${{ matrix.targets }}
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2

25
.wasm/.clippy.toml Normal file
View File

@ -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 = "{" },
]

View File

@ -235,11 +235,8 @@ unstable-unspecified = [
"ruma-push-gateway-api?/unstable-unspecified", "ruma-push-gateway-api?/unstable-unspecified",
] ]
# Private feature, only used in test / benchmarking code # Private features, only used in test / benchmarking code
__ci = [ __unstable-mscs = [
"full",
"compat-upload-signatures",
"unstable-unspecified",
"unstable-msc1767", "unstable-msc1767",
"unstable-msc2409", "unstable-msc2409",
"unstable-msc2448", "unstable-msc2448",
@ -281,7 +278,13 @@ __ci = [
"unstable-msc4108", "unstable-msc4108",
"unstable-msc4121", "unstable-msc4121",
"unstable-msc4125", "unstable-msc4125",
"unstable-msc4140" "unstable-msc4140",
]
__ci = [
"full",
"compat-upload-signatures",
"__unstable-mscs",
"unstable-unspecified",
] ]
[dependencies] [dependencies]

View File

@ -60,7 +60,7 @@ pub enum CiCmd {
NightlyAll, NightlyAll,
/// Lint default features with clippy (nightly) /// Lint default features with clippy (nightly)
ClippyDefault, ClippyDefault,
/// Lint ruma-common with clippy on a wasm target (nightly) /// Lint client features with clippy on a wasm target (nightly)
ClippyWasm, ClippyWasm,
/// Lint almost all features with clippy (nightly) /// Lint almost all features with clippy (nightly)
ClippyAll, ClippyAll,
@ -289,17 +289,15 @@ impl CiTask {
.map_err(Into::into) .map_err(Into::into)
} }
/// Lint ruma-common with clippy with the nightly version and wasm target. /// Lint ruma 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.
fn clippy_wasm(&self) -> Result<()> { fn clippy_wasm(&self) -> Result<()> {
cmd!( cmd!(
" "
rustup run {NIGHTLY} cargo clippy --target wasm32-unknown-unknown rustup run {NIGHTLY} cargo clippy --target wasm32-unknown-unknown -p ruma --features
-p ruma-common --features api,js,rand __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() .run()
.map_err(Into::into) .map_err(Into::into)
} }