mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
parent
46839a3bc5
commit
c963f68083
4 changed files with 34 additions and 6 deletions
3
crates/typos-dict/assets/allowed.csv
vendored
Normal file
3
crates/typos-dict/assets/allowed.csv
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
nilable,used in ruby community
|
||||
thead,html tag
|
||||
hardlinked,filesystem term
|
|
1
crates/typos-dict/assets/words.csv
vendored
1
crates/typos-dict/assets/words.csv
vendored
|
@ -33022,7 +33022,6 @@ nigthmares,nightmares
|
|||
nihilim,nihilism
|
||||
nihilisim,nihilism
|
||||
nihilsim,nihilism
|
||||
nilable,nillable
|
||||
nilihism,nihilism
|
||||
nimutes,minutes
|
||||
nin,inn,min,bin,nine
|
||||
|
|
Can't render this file because it is too large.
|
|
@ -68764,7 +68764,6 @@ pub static WORD_NI_CHILDREN: dictgen::DictTable<&'static [&'static str]> = dictg
|
|||
dictgen::InsensitiveStr::Ascii("hilim"),
|
||||
dictgen::InsensitiveStr::Ascii("hilisim"),
|
||||
dictgen::InsensitiveStr::Ascii("hilsim"),
|
||||
dictgen::InsensitiveStr::Ascii("lable"),
|
||||
dictgen::InsensitiveStr::Ascii("lihism"),
|
||||
dictgen::InsensitiveStr::Ascii("mutes"),
|
||||
dictgen::InsensitiveStr::Ascii("n"),
|
||||
|
@ -68817,7 +68816,6 @@ pub static WORD_NI_CHILDREN: dictgen::DictTable<&'static [&'static str]> = dictg
|
|||
&["nihilism"],
|
||||
&["nihilism"],
|
||||
&["nihilism"],
|
||||
&["nillable"],
|
||||
&["nihilism"],
|
||||
&["minutes"],
|
||||
&["inn", "min", "bin", "nine"],
|
||||
|
|
|
@ -50,17 +50,26 @@ fn generate<W: std::io::Write>(file: &mut W, dict: &[u8]) {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let disallowed_typos = varcon_words();
|
||||
let varcon_words = varcon_words();
|
||||
let allowed_words = allowed_words();
|
||||
let word_variants = proper_word_variants();
|
||||
let rows: Dict = rows
|
||||
.into_iter()
|
||||
.filter(|(typo, _)| {
|
||||
let is_disallowed = disallowed_typos.contains(&unicase::UniCase::new(typo));
|
||||
let is_disallowed = varcon_words.contains(&unicase::UniCase::new(typo));
|
||||
if is_disallowed {
|
||||
eprintln!("{:?} is disallowed", typo);
|
||||
eprintln!("{:?} is disallowed; in varcon", typo);
|
||||
}
|
||||
!is_disallowed
|
||||
})
|
||||
.filter(|(typo, _)| {
|
||||
if let Some(reason) = allowed_words.get(typo.as_ref()) {
|
||||
eprintln!("{:?} is disallowed; {}", typo, reason);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.map(|(typo, corrections)| {
|
||||
let mut new_corrections = vec![];
|
||||
for correction in corrections {
|
||||
|
@ -137,3 +146,22 @@ fn find_best_match<'c>(
|
|||
matches.sort_unstable();
|
||||
matches.into_iter().next().map(|(_, r)| r)
|
||||
}
|
||||
|
||||
fn allowed_words() -> std::collections::HashMap<String, String> {
|
||||
let allowed_path = "assets/allowed.csv";
|
||||
let data = std::fs::read(allowed_path).unwrap();
|
||||
csv::ReaderBuilder::new()
|
||||
.has_headers(false)
|
||||
.flexible(true)
|
||||
.from_reader(data.as_slice())
|
||||
.records()
|
||||
.map(Result::unwrap)
|
||||
.map(|r| {
|
||||
let mut i = r.iter();
|
||||
let mut typo = i.next().expect("typo").to_owned();
|
||||
typo.make_ascii_lowercase();
|
||||
let reason = i.next().expect("reason").to_owned();
|
||||
(typo, reason)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue