diff --git a/docs/reference.md b/docs/reference.md index 0cfabf5..1feda8a 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -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.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. | -| type..binary | | | See `default.` for child keys. Run with `--type-list` to see available ``s | +| type.. | | | See `default.` for child keys. Run with `--type-list` to see available ``s | +| type..extend_globs | \- | list of strings | File globs for matching `` | diff --git a/src/config.rs b/src/config.rs index 0f3fe91..dba0e2b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,7 @@ pub struct Config { pub files: Walk, pub default: EngineConfig, #[serde(rename = "type")] - pub type_: std::collections::HashMap, + pub type_: std::collections::HashMap, #[serde(skip)] pub overrides: EngineConfig, } @@ -49,7 +49,7 @@ impl Config { for (type_name, engine) in source.type_.iter() { self.type_ .entry(type_name.to_owned()) - .or_insert_with(EngineConfig::default) + .or_insert_with(TypeEngineConfig::default) .update(engine); } 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, + #[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)] #[serde(deny_unknown_fields, default)] #[serde(rename_all = "kebab-case")] diff --git a/src/policy.rs b/src/policy.rs index b589487..099f268 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -153,8 +153,12 @@ impl<'s> ConfigEngine<'s> { type_matcher.add_defaults(); let mut types: std::collections::HashMap<_, _> = Default::default(); 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(); - new_type_engine.update(&type_engine); + new_type_engine.update(&type_engine.engine); new_type_engine.update(&overrides); let type_config = self.init_file_config(new_type_engine); types.insert(type_name, type_config);