From 0c05b217d458f3b98616853b8bb180b7eedeca6b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 1 Sep 2023 10:19:16 -0500 Subject: [PATCH] style: Make clippy happy --- crates/codespell-dict/tests/codegen.rs | 2 +- crates/dictgen/src/trie.rs | 4 +-- crates/typos-cli/src/bin/typos-cli/args.rs | 9 ++----- crates/typos-cli/src/config.rs | 8 ++---- crates/typos-cli/src/dict.rs | 17 +++++------- crates/typos-dict/tests/verify.rs | 1 - crates/typos/src/dict.rs | 4 +-- crates/typos/src/tokens.rs | 30 +++++++++++----------- 8 files changed, 31 insertions(+), 44 deletions(-) diff --git a/crates/codespell-dict/tests/codegen.rs b/crates/codespell-dict/tests/codegen.rs index edb6e0b..734cf6c 100644 --- a/crates/codespell-dict/tests/codegen.rs +++ b/crates/codespell-dict/tests/codegen.rs @@ -7,7 +7,7 @@ fn codegen() { let content = String::from_utf8(content).unwrap(); let content = codegenrs::rustfmt(&content, None).unwrap(); - snapbox::assert_eq_path("./src/dict_codegen.rs", &content); + snapbox::assert_eq_path("./src/dict_codegen.rs", content); } #[test] diff --git a/crates/dictgen/src/trie.rs b/crates/dictgen/src/trie.rs index 03ef6ff..07b06f9 100644 --- a/crates/dictgen/src/trie.rs +++ b/crates/dictgen/src/trie.rs @@ -28,9 +28,9 @@ impl DictTrie { match child.children { DictTrieChild::Nested(n) => { let byte = bytes[i]; - let index = if (b'a'..=b'z').contains(&byte) { + let index = if byte.is_ascii_lowercase() { byte - b'a' - } else if (b'A'..=b'Z').contains(&byte) { + } else if byte.is_ascii_uppercase() { byte - b'A' } else { return self.unicode.find(word); diff --git a/crates/typos-cli/src/bin/typos-cli/args.rs b/crates/typos-cli/src/bin/typos-cli/args.rs index 03b0d33..0201084 100644 --- a/crates/typos-cli/src/bin/typos-cli/args.rs +++ b/crates/typos-cli/src/bin/typos-cli/args.rs @@ -3,10 +3,11 @@ use clap::Parser; use typos_cli::config; -#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum, Default)] pub enum Format { Silent, Brief, + #[default] Long, Json, } @@ -32,12 +33,6 @@ impl Format { } } -impl Default for Format { - fn default() -> Self { - Format::Long - } -} - #[derive(Debug, Parser)] #[command(rename_all = "kebab-case")] #[command(about, author, version)] diff --git a/crates/typos-cli/src/config.rs b/crates/typos-cli/src/config.rs index 67701a9..7ee6c3e 100644 --- a/crates/typos-cli/src/config.rs +++ b/crates/typos-cli/src/config.rs @@ -483,7 +483,9 @@ impl Eq for DictConfig {} #[derive(Debug, Copy, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "kebab-case")] +#[derive(Default)] pub enum Locale { + #[default] En, EnUs, EnGb, @@ -507,12 +509,6 @@ impl Locale { } } -impl Default for Locale { - fn default() -> Self { - Locale::En - } -} - impl std::str::FromStr for Locale { type Err = String; diff --git a/crates/typos-cli/src/dict.rs b/crates/typos-cli/src/dict.rs index a8f317e..f69abe0 100644 --- a/crates/typos-cli/src/dict.rs +++ b/crates/typos-cli/src/dict.rs @@ -18,17 +18,14 @@ impl BuiltIn { } } - pub fn correct_ident<'s, 'w>( + pub fn correct_ident<'s>( &'s self, - _ident: typos::tokens::Identifier<'w>, + _ident: typos::tokens::Identifier<'_>, ) -> Option> { None } - pub fn correct_word<'s, 'w>( - &'s self, - word_token: typos::tokens::Word<'w>, - ) -> Option> { + pub fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option> { if word_token.case() == typos::tokens::Case::None { return None; } @@ -162,11 +159,11 @@ impl BuiltIn { } impl typos::Dictionary for BuiltIn { - fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option> { + fn correct_ident<'s>(&'s self, ident: typos::tokens::Identifier<'_>) -> Option> { BuiltIn::correct_ident(self, ident) } - fn correct_word<'s, 'w>(&'s self, word: typos::tokens::Word<'w>) -> Option> { + fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option> { BuiltIn::correct_word(self, word) } } @@ -246,7 +243,7 @@ impl<'i, 'w, D: typos::Dictionary> Override<'i, 'w, D> { } impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> { - fn correct_ident<'s, 't>(&'s self, ident: typos::tokens::Identifier<'t>) -> Option> { + fn correct_ident<'s>(&'s self, ident: typos::tokens::Identifier<'_>) -> Option> { for ignored in &self.ignored_identifiers { if ignored.is_match(ident.token()) { return Some(Status::Valid); @@ -264,7 +261,7 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> { } } - fn correct_word<'s, 't>(&'s self, word: typos::tokens::Word<'t>) -> Option> { + fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option> { if word.case() == typos::tokens::Case::None { return None; } diff --git a/crates/typos-dict/tests/verify.rs b/crates/typos-dict/tests/verify.rs index 560b095..c404768 100644 --- a/crates/typos-dict/tests/verify.rs +++ b/crates/typos-dict/tests/verify.rs @@ -39,7 +39,6 @@ fn parse_dict(path: &str) -> Vec<(String, Vec)> { reader .records() - .into_iter() .map(Result::unwrap) .map(|record| { let mut iter = record.into_iter(); diff --git a/crates/typos/src/dict.rs b/crates/typos/src/dict.rs index deed6d9..53bc151 100644 --- a/crates/typos/src/dict.rs +++ b/crates/typos/src/dict.rs @@ -5,12 +5,12 @@ pub trait Dictionary: Send + Sync { /// Look up the validity of an Identifier. /// /// `None` if the status is unknown. - fn correct_ident<'s, 'w>(&'s self, ident: crate::tokens::Identifier<'w>) -> Option>; + fn correct_ident<'s>(&'s self, ident: crate::tokens::Identifier<'_>) -> Option>; /// Look up the validity of a Word. /// /// `None` if the status is unknown. - fn correct_word<'s, 'w>(&'s self, word: crate::tokens::Word<'w>) -> Option>; + fn correct_word<'s>(&'s self, word: crate::tokens::Word<'_>) -> Option>; } /// Validity of a term in a Dictionary. diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index 92b2d56..707654f 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -510,21 +510,21 @@ mod parser { #[inline] fn is_lower_hex_digit(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('a'..='f').contains(&c) || ('0'..='9').contains(&c) + ('a'..='f').contains(&c) || c.is_ascii_digit() } #[inline] fn is_upper_hex_digit(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('A'..='F').contains(&c) || ('0'..='9').contains(&c) + ('A'..='F').contains(&c) || c.is_ascii_digit() } #[inline] fn is_base64_digit(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('a'..='z').contains(&c) - || ('A'..='Z').contains(&c) - || ('0'..='9').contains(&c) + c.is_ascii_lowercase() + || c.is_ascii_uppercase() + || c.is_ascii_digit() || c == '+' || c == '/' } @@ -538,18 +538,18 @@ mod parser { #[inline] fn is_localport_char(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('a'..='z').contains(&c) - || ('A'..='Z').contains(&c) - || ('0'..='9').contains(&c) + c.is_ascii_lowercase() + || c.is_ascii_uppercase() + || c.is_ascii_digit() || "!#$%&'*+-/=?^_`{|}~().".find(c).is_some() } #[inline] fn is_domain_char(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('a'..='z').contains(&c) - || ('A'..='Z').contains(&c) - || ('0'..='9').contains(&c) + c.is_ascii_lowercase() + || c.is_ascii_uppercase() + || c.is_ascii_digit() || "-().".find(c).is_some() } @@ -568,9 +568,9 @@ mod parser { #[inline] fn is_uri_unreserved(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('a'..='z').contains(&c) - || ('A'..='Z').contains(&c) - || ('0'..='9').contains(&c) + c.is_ascii_lowercase() + || c.is_ascii_uppercase() + || c.is_ascii_digit() || "-._~".find(c).is_some() } @@ -583,7 +583,7 @@ mod parser { #[inline] fn is_scheme_char(i: impl AsChar + Copy) -> bool { let c = i.as_char(); - ('a'..='z').contains(&c) || ('0'..='9').contains(&c) || "+.-".find(c).is_some() + c.is_ascii_lowercase() || c.is_ascii_digit() || "+.-".find(c).is_some() } #[inline]