mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 10:31:02 -05:00
Merge pull request #761 from epage/rust
fix(config): Always apply type defaults
This commit is contained in:
commit
7cce285602
4 changed files with 113 additions and 84 deletions
|
@ -1,5 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use kstring::KString;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[serde(default)]
|
||||
|
@ -148,40 +150,25 @@ impl Walk {
|
|||
#[serde(default)]
|
||||
#[serde(transparent)]
|
||||
pub struct TypeEngineConfig {
|
||||
pub patterns: std::collections::HashMap<kstring::KString, GlobEngineConfig>,
|
||||
pub patterns: std::collections::HashMap<KString, GlobEngineConfig>,
|
||||
}
|
||||
|
||||
impl TypeEngineConfig {
|
||||
pub fn from_defaults() -> Self {
|
||||
let empty = Self::default();
|
||||
Self {
|
||||
patterns: empty.patterns().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, source: &Self) {
|
||||
for (type_name, engine) in source.patterns.iter() {
|
||||
self.patterns
|
||||
.entry(type_name.to_owned())
|
||||
.or_insert_with(GlobEngineConfig::default)
|
||||
.update(engine);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn patterns(&self) -> impl Iterator<Item = (kstring::KString, GlobEngineConfig)> {
|
||||
let mut patterns = self.patterns.clone();
|
||||
patterns
|
||||
.entry("lock".into())
|
||||
.or_insert_with(|| GlobEngineConfig {
|
||||
let patterns = [
|
||||
(
|
||||
KString::from("lock"),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
check_file: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
patterns
|
||||
.entry("vim".into())
|
||||
.or_insert_with(|| GlobEngineConfig {
|
||||
},
|
||||
),
|
||||
(
|
||||
KString::from("vim"),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
dict: Some(DictConfig {
|
||||
|
@ -192,10 +179,11 @@ impl TypeEngineConfig {
|
|||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
patterns
|
||||
.entry("vimscript".into())
|
||||
.or_insert_with(|| GlobEngineConfig {
|
||||
},
|
||||
),
|
||||
(
|
||||
KString::from("vimscript"),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
dict: Some(DictConfig {
|
||||
|
@ -206,10 +194,11 @@ impl TypeEngineConfig {
|
|||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
patterns
|
||||
.entry("rust".into())
|
||||
.or_insert_with(|| GlobEngineConfig {
|
||||
},
|
||||
),
|
||||
(
|
||||
KString::from("rust"),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
dict: Some(DictConfig {
|
||||
|
@ -223,10 +212,11 @@ impl TypeEngineConfig {
|
|||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
patterns
|
||||
.entry("py".into())
|
||||
.or_insert_with(|| GlobEngineConfig {
|
||||
},
|
||||
),
|
||||
(
|
||||
KString::from("py"),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
dict: Some(DictConfig {
|
||||
|
@ -237,17 +227,37 @@ impl TypeEngineConfig {
|
|||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
patterns
|
||||
.entry("cert".into())
|
||||
.or_insert_with(|| GlobEngineConfig {
|
||||
},
|
||||
),
|
||||
(
|
||||
KString::from("cert"),
|
||||
GlobEngineConfig {
|
||||
extend_glob: Vec::new(),
|
||||
engine: EngineConfig {
|
||||
check_file: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
patterns.into_iter()
|
||||
},
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect();
|
||||
Self { patterns }
|
||||
}
|
||||
|
||||
pub fn update(&mut self, source: &Self) {
|
||||
for (type_name, engine) in source.patterns.iter() {
|
||||
self.patterns
|
||||
.entry(type_name.to_owned())
|
||||
.or_insert_with(GlobEngineConfig::default)
|
||||
.update(engine);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn patterns(&self) -> impl Iterator<Item = (kstring::KString, GlobEngineConfig)> {
|
||||
let mut engine = Self::from_defaults();
|
||||
engine.update(self);
|
||||
engine.patterns.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
[type.rust]
|
||||
check-filename = false
|
||||
|
||||
[default.extend-words]
|
||||
foo = "bar"
|
||||
|
||||
[files]
|
||||
extend-exclude = [
|
||||
"_typos.toml"
|
||||
]
|
1
crates/typos-cli/tests/cmd/extend-builtin-dict.in/foo.rs
Normal file
1
crates/typos-cli/tests/cmd/extend-builtin-dict.in/foo.rs
Normal file
|
@ -0,0 +1 @@
|
|||
flate2
|
8
crates/typos-cli/tests/cmd/extend-builtin-dict.toml
Normal file
8
crates/typos-cli/tests/cmd/extend-builtin-dict.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
bin.name = "typos"
|
||||
args = ""
|
||||
stdin = '''
|
||||
\n\n
|
||||
Destory
|
||||
'''
|
||||
stdout = ""
|
||||
stderr = ""
|
Loading…
Reference in a new issue