diff --git a/crates/codespell-dict/tests/codegen.rs b/crates/codespell-dict/tests/codegen.rs index edb6e0bb6..734cf6c82 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 03ef6ffc8..07b06f951 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 03b0d33a4..02010845b 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 67701a9db..7ee6c3e0d 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 a8f317e1a..f69abe0f7 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 560b095eb..c40476888 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 deed6d9c1..53bc151cf 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 92b2d56de..707654f58 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]