Merge pull request #761 from epage/rust

fix(config): Always apply type defaults
This commit is contained in:
Ed Page 2023-06-22 10:12:44 -05:00 committed by GitHub
commit 7cce285602
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 84 deletions

View file

@ -1,5 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use kstring::KString;
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
#[serde(default)] #[serde(default)]
@ -148,15 +150,99 @@ impl Walk {
#[serde(default)] #[serde(default)]
#[serde(transparent)] #[serde(transparent)]
pub struct TypeEngineConfig { pub struct TypeEngineConfig {
pub patterns: std::collections::HashMap<kstring::KString, GlobEngineConfig>, pub patterns: std::collections::HashMap<KString, GlobEngineConfig>,
} }
impl TypeEngineConfig { impl TypeEngineConfig {
pub fn from_defaults() -> Self { pub fn from_defaults() -> Self {
let empty = Self::default(); let patterns = [
Self { (
patterns: empty.patterns().collect(), KString::from("lock"),
} GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
check_file: Some(false),
..Default::default()
},
},
),
(
KString::from("vim"),
GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"windo".into() => "windo".into(),
},
..Default::default()
}),
..Default::default()
},
},
),
(
KString::from("vimscript"),
GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"windo".into() => "windo".into(),
},
..Default::default()
}),
..Default::default()
},
},
),
(
KString::from("rust"),
GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"flate2".into() => "flate2".into(),
},
extend_words: maplit::hashmap! {
"ser".into() => "ser".into(),
},
..Default::default()
}),
..Default::default()
},
},
),
(
KString::from("py"),
GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"NDArray".into() => "NDArray".into(),
},
..Default::default()
}),
..Default::default()
},
},
),
(
KString::from("cert"),
GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
check_file: Some(false),
..Default::default()
},
},
),
]
.into_iter()
.collect();
Self { patterns }
} }
pub fn update(&mut self, source: &Self) { pub fn update(&mut self, source: &Self) {
@ -169,85 +255,9 @@ impl TypeEngineConfig {
} }
pub fn patterns(&self) -> impl Iterator<Item = (kstring::KString, GlobEngineConfig)> { pub fn patterns(&self) -> impl Iterator<Item = (kstring::KString, GlobEngineConfig)> {
let mut patterns = self.patterns.clone(); let mut engine = Self::from_defaults();
patterns engine.update(self);
.entry("lock".into()) engine.patterns.into_iter()
.or_insert_with(|| GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
check_file: Some(false),
..Default::default()
},
});
patterns
.entry("vim".into())
.or_insert_with(|| GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"windo".into() => "windo".into(),
},
..Default::default()
}),
..Default::default()
},
});
patterns
.entry("vimscript".into())
.or_insert_with(|| GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"windo".into() => "windo".into(),
},
..Default::default()
}),
..Default::default()
},
});
patterns
.entry("rust".into())
.or_insert_with(|| GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"flate2".into() => "flate2".into(),
},
extend_words: maplit::hashmap! {
"ser".into() => "ser".into(),
},
..Default::default()
}),
..Default::default()
},
});
patterns
.entry("py".into())
.or_insert_with(|| GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
dict: Some(DictConfig {
extend_identifiers: maplit::hashmap! {
"NDArray".into() => "NDArray".into(),
},
..Default::default()
}),
..Default::default()
},
});
patterns
.entry("cert".into())
.or_insert_with(|| GlobEngineConfig {
extend_glob: Vec::new(),
engine: EngineConfig {
check_file: Some(false),
..Default::default()
},
});
patterns.into_iter()
} }
} }

View file

@ -0,0 +1,10 @@
[type.rust]
check-filename = false
[default.extend-words]
foo = "bar"
[files]
extend-exclude = [
"_typos.toml"
]

View file

@ -0,0 +1 @@
flate2

View file

@ -0,0 +1,8 @@
bin.name = "typos"
args = ""
stdin = '''
\n\n
Destory
'''
stdout = ""
stderr = ""