From e2375ed72ed1902a7b662c1e13ebb1ee71467418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 18 Mar 2022 13:47:13 +0100 Subject: [PATCH] xtask: Add typos check --- .github/workflows/nightly.yml | 9 ++++++++ .typos.toml | 5 +++++ crates/ruma-common/src/events/reaction.rs | 2 +- crates/ruma-common/src/push/condition.rs | 2 +- crates/ruma-common/src/serde/strings.rs | 4 ++-- crates/ruma-common/tests/api/no_fields.rs | 2 +- .../ruma-identifiers-validation/CHANGELOG.md | 2 +- xtask/src/ci.rs | 22 +++++++++++++------ 8 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 .typos.toml diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 62898d35..9c46ebbe 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -33,3 +33,12 @@ jobs: with: command: run args: -p xtask --no-default-features ci nightly + + typos: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + - name: Check the spelling of the files in our repo + uses: crate-ci/typos@master diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 00000000..ef492878 --- /dev/null +++ b/.typos.toml @@ -0,0 +1,5 @@ +[default.extend-words] +# Remove this once base64 gets correctly ignored by typos +# Or if we're able to ignore certain lines. +NAX = "NAX" +Nd = "Nd" diff --git a/crates/ruma-common/src/events/reaction.rs b/crates/ruma-common/src/events/reaction.rs index 4d26761d..e1693c21 100644 --- a/crates/ruma-common/src/events/reaction.rs +++ b/crates/ruma-common/src/events/reaction.rs @@ -37,7 +37,7 @@ impl From for ReactionEventContent { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[serde(tag = "rel_type", rename = "m.annotation")] pub struct Relation { - /// The event that is being annoted. + /// The event that is being annotated. pub event_id: Box, /// A string that indicates the annotation being applied. diff --git a/crates/ruma-common/src/push/condition.rs b/crates/ruma-common/src/push/condition.rs index 68f87ecf..43769aa0 100644 --- a/crates/ruma-common/src/push/condition.rs +++ b/crates/ruma-common/src/push/condition.rs @@ -456,7 +456,7 @@ mod tests { assert!("foobar".matches_pattern("foo*", false)); assert!("foo bar".matches_pattern("foo*", false)); assert!(!"foo".matches_pattern("foo?", false)); - assert!("foo".matches_pattern("fo?", false)); + assert!("fooo".matches_pattern("foo?", false)); assert!("FOO".matches_pattern("foo", false)); assert!("".matches_pattern("", false)); assert!("".matches_pattern("*", false)); diff --git a/crates/ruma-common/src/serde/strings.rs b/crates/ruma-common/src/serde/strings.rs index d3cfc0b6..064f2c59 100644 --- a/crates/ruma-common/src/serde/strings.rs +++ b/crates/ruma-common/src/serde/strings.rs @@ -31,8 +31,8 @@ where } } -/// Serde serializiation decorator to map None to an empty String, -/// and forward Somes to the Serialize implementation for T. +/// Serde serializiation decorator to map `None` to an empty `String`, +/// and forward `Some`s to the `Serialize` implementation for `T`. /// /// To be used like this: /// `#[serde(serialize_with = "empty_string_as_none")]` diff --git a/crates/ruma-common/tests/api/no_fields.rs b/crates/ruma-common/tests/api/no_fields.rs index 6376cebb..e9bdc263 100644 --- a/crates/ruma-common/tests/api/no_fields.rs +++ b/crates/ruma-common/tests/api/no_fields.rs @@ -68,7 +68,7 @@ fn empty_post_response_http_repr() { let res = post::Response {}; let http_res = res.try_into_http_response::>().unwrap(); - // For the reponse, the body should be an empty dict again... + // For the response, the body should be an empty dict again... assert_eq!(http_res.body(), b"{}"); } diff --git a/crates/ruma-identifiers-validation/CHANGELOG.md b/crates/ruma-identifiers-validation/CHANGELOG.md index 7e7b22a7..2c71f1fa 100644 --- a/crates/ruma-identifiers-validation/CHANGELOG.md +++ b/crates/ruma-identifiers-validation/CHANGELOG.md @@ -26,7 +26,7 @@ Breaking changes: Breaking changes: -* Fix a typo in a public function name: `user_id::localpart_is_fully_{comforming => conforming}` +* Fix a typo in a public function name: `user_id::localpart_is_fully_conforming` # 0.3.0 diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 1e536e28..3f5f4b06 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -39,6 +39,8 @@ pub enum CiCmd { Dependencies, /// Check spec links point to a recent version (nightly) SpecLinks, + /// Check typos + Typos, } /// Task to run CI tests. @@ -70,6 +72,7 @@ impl CiTask { Some(CiCmd::Clippy) => self.clippy()?, Some(CiCmd::Dependencies) => self.dependencies()?, Some(CiCmd::SpecLinks) => check_spec_links(&self.project_root.join("crates"))?, + Some(CiCmd::Typos) => self.typos()?, None => { self.build_msrv().and(self.build_stable()).and(self.build_nightly())?; } @@ -136,14 +139,9 @@ impl CiTask { // Check dependencies being sorted let dependencies_res = self.dependencies(); // Check that all links point to the same version of the spec - let spec_links = check_spec_links(&self.project_root.join("crates")); + let spec_links_res = check_spec_links(&self.project_root.join("crates")); - fmt_res - .and(check_full_res) - .and(clippy_res) - .and(dependencies_res) - .map_err(Into::into) - .and(spec_links) + fmt_res.and(check_full_res).and(clippy_res).and(dependencies_res).and(spec_links_res) } /// Check the formatting with the nightly version. @@ -189,4 +187,14 @@ impl CiTask { .run() .map_err(Into::into) } + + /// Check the typos. + fn typos(&self) -> Result<()> { + if cmd!("typos --version").run().is_err() { + return Err( + "Could not find typos. Install it by running `cargo install typos-cli`".into() + ); + } + cmd!("typos").run().map_err(Into::into) + } }