Skip to content

Commit

Permalink
style: Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 1, 2023
1 parent 67ca12a commit 0c05b21
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 44 deletions.
2 changes: 1 addition & 1 deletion crates/codespell-dict/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions crates/dictgen/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl<V> DictTrie<V> {
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);
Expand Down
9 changes: 2 additions & 7 deletions crates/typos-cli/src/bin/typos-cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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)]
Expand Down
8 changes: 2 additions & 6 deletions crates/typos-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -507,12 +509,6 @@ impl Locale {
}
}

impl Default for Locale {
fn default() -> Self {
Locale::En
}
}

impl std::str::FromStr for Locale {
type Err = String;

Expand Down
17 changes: 7 additions & 10 deletions crates/typos-cli/src/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Status<'s>> {
None
}

pub fn correct_word<'s, 'w>(
&'s self,
word_token: typos::tokens::Word<'w>,
) -> Option<Status<'s>> {
pub fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option<Status<'s>> {
if word_token.case() == typos::tokens::Case::None {
return None;
}
Expand Down Expand Up @@ -162,11 +159,11 @@ impl BuiltIn {
}

impl typos::Dictionary for BuiltIn {
fn correct_ident<'s, 'w>(&'s self, ident: typos::tokens::Identifier<'w>) -> Option<Status<'s>> {
fn correct_ident<'s>(&'s self, ident: typos::tokens::Identifier<'_>) -> Option<Status<'s>> {
BuiltIn::correct_ident(self, ident)
}

fn correct_word<'s, 'w>(&'s self, word: typos::tokens::Word<'w>) -> Option<Status<'s>> {
fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
BuiltIn::correct_word(self, word)
}
}
Expand Down Expand Up @@ -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<Status<'s>> {
fn correct_ident<'s>(&'s self, ident: typos::tokens::Identifier<'_>) -> Option<Status<'s>> {
for ignored in &self.ignored_identifiers {
if ignored.is_match(ident.token()) {
return Some(Status::Valid);
Expand All @@ -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<Status<'s>> {
fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
if word.case() == typos::tokens::Case::None {
return None;
}
Expand Down
1 change: 0 additions & 1 deletion crates/typos-dict/tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fn parse_dict(path: &str) -> Vec<(String, Vec<String>)> {

reader
.records()
.into_iter()
.map(Result::unwrap)
.map(|record| {
let mut iter = record.into_iter();
Expand Down
4 changes: 2 additions & 2 deletions crates/typos/src/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Status<'s>>;
fn correct_ident<'s>(&'s self, ident: crate::tokens::Identifier<'_>) -> Option<Status<'s>>;

/// 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<Status<'s>>;
fn correct_word<'s>(&'s self, word: crate::tokens::Word<'_>) -> Option<Status<'s>>;
}

/// Validity of a term in a Dictionary.
Expand Down
30 changes: 15 additions & 15 deletions crates/typos/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '/'
}
Expand All @@ -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()
}

Expand All @@ -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()
}

Expand All @@ -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]
Expand Down

0 comments on commit 0c05b21

Please sign in to comment.