mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-01 05:20:59 -05:00
parent
c71c9f4f84
commit
2a7bd5b046
3 changed files with 25 additions and 4 deletions
|
@ -31,4 +31,5 @@ Configuration is read from the following (in precedence order)
|
||||||
| default.locale | --locale | en, en-us, en-gb, en-ca, en-au | English dialect to correct to. |
|
| default.locale | --locale | en, en-us, en-gb, en-ca, en-au | English dialect to correct to. |
|
||||||
| default.extend-identifiers | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
|
| default.extend-identifiers | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
|
||||||
| default.extend-words | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
|
| default.extend-words | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
|
||||||
| type.<name>.binary | <varied> | <varied> | See `default.` for child keys. Run with `--type-list` to see available `<name>`s |
|
| type.<name>.<field> | <varied> | <varied> | See `default.` for child keys. Run with `--type-list` to see available `<name>`s |
|
||||||
|
| type.<name>.extend_globs | \- | list of strings | File globs for matching `<name>` |
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub struct Config {
|
||||||
pub files: Walk,
|
pub files: Walk,
|
||||||
pub default: EngineConfig,
|
pub default: EngineConfig,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub type_: std::collections::HashMap<kstring::KString, EngineConfig>,
|
pub type_: std::collections::HashMap<kstring::KString, TypeEngineConfig>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub overrides: EngineConfig,
|
pub overrides: EngineConfig,
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ impl Config {
|
||||||
for (type_name, engine) in source.type_.iter() {
|
for (type_name, engine) in source.type_.iter() {
|
||||||
self.type_
|
self.type_
|
||||||
.entry(type_name.to_owned())
|
.entry(type_name.to_owned())
|
||||||
.or_insert_with(EngineConfig::default)
|
.or_insert_with(TypeEngineConfig::default)
|
||||||
.update(engine);
|
.update(engine);
|
||||||
}
|
}
|
||||||
self.overrides.update(&source.overrides);
|
self.overrides.update(&source.overrides);
|
||||||
|
@ -137,6 +137,22 @@ impl Walk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(deny_unknown_fields, default)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub struct TypeEngineConfig {
|
||||||
|
pub extend_glob: Vec<kstring::KString>,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub engine: EngineConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TypeEngineConfig {
|
||||||
|
pub fn update(&mut self, source: &TypeEngineConfig) {
|
||||||
|
self.extend_glob.extend(source.extend_glob.iter().cloned());
|
||||||
|
self.engine.update(&source.engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(deny_unknown_fields, default)]
|
#[serde(deny_unknown_fields, default)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
|
|
@ -153,8 +153,12 @@ impl<'s> ConfigEngine<'s> {
|
||||||
type_matcher.add_defaults();
|
type_matcher.add_defaults();
|
||||||
let mut types: std::collections::HashMap<_, _> = Default::default();
|
let mut types: std::collections::HashMap<_, _> = Default::default();
|
||||||
for (type_name, type_engine) in type_.into_iter() {
|
for (type_name, type_engine) in type_.into_iter() {
|
||||||
|
for glob in type_engine.extend_glob.iter() {
|
||||||
|
type_matcher.add(type_name.as_str(), glob.as_str())?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut new_type_engine = default.clone();
|
let mut new_type_engine = default.clone();
|
||||||
new_type_engine.update(&type_engine);
|
new_type_engine.update(&type_engine.engine);
|
||||||
new_type_engine.update(&overrides);
|
new_type_engine.update(&overrides);
|
||||||
let type_config = self.init_file_config(new_type_engine);
|
let type_config = self.init_file_config(new_type_engine);
|
||||||
types.insert(type_name, type_config);
|
types.insert(type_name, type_config);
|
||||||
|
|
Loading…
Reference in a new issue