mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-22 07:32:18 -05:00
style: Make clippy happy
This commit is contained in:
parent
063ac6d4b5
commit
267121b5d6
12 changed files with 48 additions and 56 deletions
|
@ -13,8 +13,7 @@ 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() {
|
||||
|
@ -22,12 +21,12 @@ pub fn generate_map<'d, W: std::io::Write, V: std::fmt::Display>(
|
|||
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;
|
||||
|
@ -35,10 +34,10 @@ pub fn generate_map<'d, W: std::io::Write, V: std::fmt::Display>(
|
|||
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(())
|
||||
|
|
|
@ -13,8 +13,7 @@ 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() {
|
||||
|
@ -22,12 +21,12 @@ pub fn generate_table<'d, W: std::io::Write, V: std::fmt::Display>(
|
|||
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;
|
||||
|
@ -35,10 +34,10 @@ pub fn generate_table<'d, W: std::io::Write, V: std::fmt::Display>(
|
|||
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(())
|
||||
|
|
|
@ -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)?;
|
||||
|
@ -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,
|
||||
|
@ -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,")?;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}`")),
|
||||
", "
|
||||
)
|
||||
)?;
|
||||
|
@ -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}`")),
|
||||
", "
|
||||
)
|
||||
)?;
|
||||
|
@ -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}",);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}")?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:?}")),
|
||||
" | "
|
||||
)
|
||||
)
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -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()),
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue