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 Jul 26, 2024
1 parent 063ac6d commit 267121b
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 56 deletions.
13 changes: 6 additions & 7 deletions crates/dictgen/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ pub fn generate_map<'d, W: std::io::Write, V: std::fmt::Display>(

writeln!(
file,
"pub static {}: dictgen::DictTable<{}> = dictgen::DictTable {{",
name, value_type
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
)?;
writeln!(file, " keys: &[")?;
for (key, _value) in data.iter() {
smallest = std::cmp::min(smallest, key.len());
largest = std::cmp::max(largest, key.len());

let key = if key.is_ascii() {
format!("dictgen::InsensitiveStr::Ascii({:?})", key)
format!("dictgen::InsensitiveStr::Ascii({key:?})")
} else {
format!("dictgen::InsensitiveStr::Unicode({:?})", key)
format!("dictgen::InsensitiveStr::Unicode({key:?})")
};

writeln!(file, " {},", key)?;
writeln!(file, " {key},")?;
}
if largest == 0 {
smallest = 0;
}
writeln!(file, " ],")?;
writeln!(file, " values: &[")?;
for (_key, value) in data.iter() {
writeln!(file, " {},", value)?;
writeln!(file, " {value},")?;
}
writeln!(file, " ],")?;
writeln!(file, " range: {}..={},", smallest, largest)?;
writeln!(file, " range: {smallest}..={largest},")?;
writeln!(file, "}};")?;

Ok(())
Expand Down
13 changes: 6 additions & 7 deletions crates/dictgen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ pub fn generate_table<'d, W: std::io::Write, V: std::fmt::Display>(

writeln!(
file,
"pub static {}: dictgen::DictTable<{}> = dictgen::DictTable {{",
name, value_type
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
)?;
writeln!(file, " keys: &[")?;
for (key, _value) in data.iter() {
smallest = std::cmp::min(smallest, key.len());
largest = std::cmp::max(largest, key.len());

let key = if key.is_ascii() {
format!("dictgen::InsensitiveStr::Ascii({:?})", key)
format!("dictgen::InsensitiveStr::Ascii({key:?})")
} else {
format!("dictgen::InsensitiveStr::Unicode({:?})", key)
format!("dictgen::InsensitiveStr::Unicode({key:?})")
};

writeln!(file, " {},", key)?;
writeln!(file, " {key},")?;
}
if largest == 0 {
smallest = 0;
}
writeln!(file, " ],")?;
writeln!(file, " values: &[")?;
for (_key, value) in data.iter() {
writeln!(file, " {},", value)?;
writeln!(file, " {value},")?;
}
writeln!(file, " ],")?;
writeln!(file, " range: {}..={},", smallest, largest)?;
writeln!(file, " range: {smallest}..={largest},")?;
writeln!(file, "}};")?;

Ok(())
Expand Down
25 changes: 11 additions & 14 deletions crates/dictgen/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ mod codegen {
let mut root = DynRoot::new(data);
root.burst(limit);

let unicode_table_name = format!("{}_UNICODE_TABLE", prefix);
let unicode_table_name = format!("{prefix}_UNICODE_TABLE");

writeln!(
file,
"pub static {}_TRIE: dictgen::DictTrie<{}> = dictgen::DictTrie {{",
prefix, value_type
"pub static {prefix}_TRIE: dictgen::DictTrie<{value_type}> = dictgen::DictTrie {{"
)?;
writeln!(file, " root: &{},", gen_node_name(prefix, ""))?;
writeln!(file, " unicode: &{},", &unicode_table_name)?;
Expand All @@ -118,8 +117,7 @@ mod codegen {
let children_name = gen_children_name(prefix, &start);
writeln!(
file,
"static {}: dictgen::DictTrieNode<{}> = dictgen::DictTrieNode {{",
node_name, value_type
"static {node_name}: dictgen::DictTrieNode<{value_type}> = dictgen::DictTrieNode {{"
)?;
writeln!(
file,
Expand All @@ -128,7 +126,7 @@ mod codegen {
children_name
)?;
if let Some(value) = node.value.as_ref() {
writeln!(file, " value: Some({}),", value)?;
writeln!(file, " value: Some({value}),")?;
} else {
writeln!(file, " value: None,")?;
}
Expand All @@ -139,13 +137,12 @@ mod codegen {
DynChild::Nested(n) => {
writeln!(
file,
"static {}: [Option<&dictgen::DictTrieNode<{}>>; 26] = [",
children_name, value_type,
"static {children_name}: [Option<&dictgen::DictTrieNode<{value_type}>>; 26] = [",
)?;
for b in b'a'..=b'z' {
if let Some(child) = n.get(&b) {
let c = b as char;
let next_start = format!("{}{}", start, c);
let next_start = format!("{start}{c}");
writeln!(file, " Some(&{}),", gen_node_name(prefix, &next_start))?;
nodes.push((next_start, child));
} else {
Expand All @@ -171,21 +168,21 @@ mod codegen {

fn gen_node_name(prefix: &str, start: &str) -> String {
if start.is_empty() {
format!("{}_NODE", prefix)
format!("{prefix}_NODE")
} else {
let mut start = start.to_owned();
start.make_ascii_uppercase();
format!("{}_{}_NODE", prefix, start)
format!("{prefix}_{start}_NODE")
}
}

fn gen_children_name(prefix: &str, start: &str) -> String {
if start.is_empty() {
format!("{}_CHILDREN", prefix)
format!("{prefix}_CHILDREN")
} else {
let mut start = start.to_owned();
start.make_ascii_uppercase();
format!("{}_{}_CHILDREN", prefix, start)
format!("{prefix}_{start}_CHILDREN")
}
}

Expand All @@ -212,7 +209,7 @@ mod codegen {
let mut empty = None;
for (key, value) in data {
if existing.contains(key) {
panic!("Duplicate present: {}", key);
panic!("Duplicate present: {key}");
}
existing.insert(key);

Expand Down
4 changes: 2 additions & 2 deletions crates/misspell-dict/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ fn parse_dict(raw: &str) -> Words<'_> {
vec![captures.get(2).unwrap().as_str()],
);
} else {
eprintln!("Unknown line: {}", line);
eprintln!("Unknown line: {line}");
}
}
}

if !bad.is_empty() {
panic!("Failed parsing; found extra words: {:#?}", bad);
panic!("Failed parsing; found extra words: {bad:#?}");
}

Words {
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
for pattern in walk_policy.extend_exclude.iter() {
overrides
.add(&format!("!{}", pattern))
.add(&format!("!{pattern}"))
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
}
let overrides = overrides
Expand Down
12 changes: 6 additions & 6 deletions crates/typos-cli/src/bin/typos-cli/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn print_brief_correction(msg: &Typo<'_>) -> Result<(), std::io::Error> {
context_display(&msg.context),
msg.typo,
itertools::join(
corrections.iter().map(|s| format!("`{good}{}{reset}`", s)),
corrections.iter().map(|s| format!("`{good}{s}{reset}`")),
", "
)
)?;
Expand Down Expand Up @@ -192,7 +192,7 @@ fn print_long_correction(msg: &Typo<'_>) -> Result<(), std::io::Error> {
"{error}error{reset}: `{error}{}{reset}` should be {}",
msg.typo,
itertools::join(
corrections.iter().map(|s| format!("`{good}{}{reset}`", s)),
corrections.iter().map(|s| format!("`{good}{s}{reset}`")),
", "
)
)?;
Expand Down Expand Up @@ -305,7 +305,7 @@ mod tests {
];
for (i, ch) in latin_cyrillic_chars.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(1, width, "latin_cyrillic[{}]: {}", i, ch,);
assert_eq!(1, width, "latin_cyrillic[{i}]: {ch}",);
}
}

Expand All @@ -319,7 +319,7 @@ mod tests {
];
for (i, ch) in cjk_chars.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(2, width, "cjk[{}]: {}", i, ch);
assert_eq!(2, width, "cjk[{i}]: {ch}");
}
}

Expand All @@ -340,7 +340,7 @@ mod tests {
];
for (i, ch) in simple_emojis.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(2, width, "emoji[{}]: {}", i, ch);
assert_eq!(2, width, "emoji[{i}]: {ch}");
}
}

Expand All @@ -352,7 +352,7 @@ mod tests {
];
for (i, ch) in zwj_sequences.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(2, width, "zwj[{}]: {}", i, ch);
assert_eq!(2, width, "zwj[{i}]: {ch}");
}
}
}
2 changes: 1 addition & 1 deletion crates/typos-cli/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl FileChecker for DiffTypos {
let stdout = std::io::stdout();
let mut handle = stdout.lock();
for line in diff {
write!(handle, "{}", line)?;
write!(handle, "{line}")?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/typos-dict/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn generate<W: std::io::Write>(file: &mut W, prefix: &str, dict: &[u8]) {
let key = record_fields.next().unwrap();
let value = format!(
"&[{}]",
itertools::join(record_fields.map(|field| format!(r#""{}""#, field)), ", ")
itertools::join(record_fields.map(|field| format!(r#""{field}""#)), ", ")
);
(key, value)
}),
Expand Down
4 changes: 2 additions & 2 deletions crates/typos-dict/tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ fn process<S: Into<String>>(
.filter(|(typo, _)| {
let is_disallowed = varcon_words.contains(&UniCase::new(typo));
if is_disallowed {
eprintln!("{:?} is disallowed; in varcon", typo);
eprintln!("{typo:?} is disallowed; in varcon");
}
!is_disallowed
})
.filter(|(typo, _)| {
if let Some(reason) = allowed_words.get(typo.as_ref()) {
eprintln!("{:?} is disallowed; {}", typo, reason);
eprintln!("{typo:?} is disallowed; {reason}");
false
} else {
true
Expand Down
13 changes: 5 additions & 8 deletions crates/typos-vars/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ fn generate_variations<W: Write>(file: &mut W) {
file,
" {}",
itertools::join(
CATEGORIES
.iter()
.map(|c| format!("crate::Category::{:?}", c)),
CATEGORIES.iter().map(|c| format!("crate::Category::{c:?}")),
" | "
)
)
Expand All @@ -71,8 +69,7 @@ fn generate_variations<W: Write>(file: &mut W) {
for (index, category) in CATEGORIES.iter().enumerate() {
writeln!(
file,
" crate::Category::{:?} => options[{}],",
category, index
" crate::Category::{category:?} => options[{index}],"
)
.unwrap();
}
Expand Down Expand Up @@ -108,7 +105,7 @@ fn generate_variations<W: Write>(file: &mut W) {

let no_invalid = entry_sets.values().all(|data| !is_always_invalid(data));
writeln!(file).unwrap();
writeln!(file, "pub const NO_INVALID: bool = {:?};", no_invalid,).unwrap();
writeln!(file, "pub const NO_INVALID: bool = {no_invalid:?};",).unwrap();

writeln!(file).unwrap();
for (symbol, entry) in entries.iter() {
Expand All @@ -120,14 +117,14 @@ fn generate_variations<W: Write>(file: &mut W) {
}

fn generate_entry(file: &mut impl Write, symbol: &str, entry: &varcon_core::Entry) {
writeln!(file, "pub(crate) static {}: VariantsMap = [", symbol).unwrap();
writeln!(file, "pub(crate) static {symbol}: VariantsMap = [").unwrap();
for category in &CATEGORIES {
let corrections = collect_correct(entry, *category);
let mut corrections: Vec<_> = corrections.iter().collect();
corrections.sort_unstable();
writeln!(file, " &[").unwrap();
for correction in &corrections {
writeln!(file, " {:?},", correction).unwrap();
writeln!(file, " {correction:?},").unwrap();
}
writeln!(file, " ],").unwrap();
}
Expand Down
8 changes: 4 additions & 4 deletions crates/typos/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,20 +773,20 @@ impl<'t> Word<'t> {
let mut item = itr.next().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("{:?} is nothing", token),
format!("{token:?} is nothing"),
)
})?;
if item.offset != 0 {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("{:?} has padding", token),
format!("{token:?} has padding"),
));
}
item.offset += offset;
if itr.next().is_some() {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("{:?} is multiple words", token),
format!("{token:?} is multiple words"),
));
}
Ok(item)
Expand Down Expand Up @@ -1407,7 +1407,7 @@ mod test {
// A 31-character hexadecimal string: too short to be a hash.
("D41D8CD98F00B204E9800998ECF8427", false),
] {
let input = format!("Hello {} World", hashlike);
let input = format!("Hello {hashlike} World");
let mut expected: Vec<Identifier<'_>> = vec![
Identifier::new_unchecked("Hello", Case::None, 0),
Identifier::new_unchecked("World", Case::None, 7+hashlike.len()),
Expand Down
6 changes: 3 additions & 3 deletions crates/varcon/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
write!(file, " Type {{").unwrap();
write!(file, "category: Category::{:?}, ", t.category).unwrap();
if let Some(tag) = t.tag {
write!(file, "tag: Some(Tag::{:?}), ", tag).unwrap();
write!(file, "tag: Some(Tag::{tag:?}), ").unwrap();
} else {
write!(file, "tag: {:?}, ", t.tag).unwrap();
}
Expand All @@ -60,7 +60,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
}
writeln!(file, " ],").unwrap();
if let Some(pos) = entry.pos {
write!(file, " pos: Some(Pos::{:?}),", pos).unwrap();
write!(file, " pos: Some(Pos::{pos:?}),").unwrap();
} else {
write!(file, " pos: {:?},", entry.pos).unwrap();
}
Expand All @@ -77,7 +77,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
writeln!(file, " ],").unwrap();
writeln!(file, " notes: &[").unwrap();
for note in &cluster.notes {
writeln!(file, " {:?},", note).unwrap();
writeln!(file, " {note:?},").unwrap();
}
writeln!(file, " ],").unwrap();
writeln!(file, " }},").unwrap();
Expand Down

0 comments on commit 267121b

Please sign in to comment.