diff --git a/src/config.rs b/src/config.rs index d1a6d20..80903f6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -62,6 +62,16 @@ pub trait FileSource { fn ignore_hex(&self) -> Option { None } + + /// Allow identifiers to include digits, in addition to letters + fn identifier_include_digits(&self) -> Option { + None + } + + /// Specify additional characters to be included in identifiers + fn identifier_include_chars(&self) -> Option<&str> { + None + } } #[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)] @@ -223,6 +233,8 @@ pub struct FileConfig { pub check_filename: Option, pub check_file: Option, pub ignore_hex: Option, + pub identifier_include_digits: Option, + pub identifier_include_chars: Option, } impl FileConfig { @@ -236,6 +248,12 @@ impl FileConfig { if let Some(source) = source.ignore_hex() { self.ignore_hex = Some(source); } + if let Some(source) = source.identifier_include_digits() { + self.identifier_include_digits = Some(source); + } + if let Some(source) = source.identifier_include_chars() { + self.identifier_include_chars = Some(source.to_owned()); + } } pub fn check_filename(&self) -> bool { @@ -249,6 +267,17 @@ impl FileConfig { pub fn ignore_hex(&self) -> bool { self.ignore_hex.unwrap_or(true) } + + pub fn identifier_include_digits(&self) -> bool { + self.identifier_include_digits.unwrap_or(true) + } + + pub fn identifier_include_chars(&self) -> &str { + self.identifier_include_chars + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("_'") + } } impl FileSource for FileConfig { @@ -263,6 +292,14 @@ impl FileSource for FileConfig { fn ignore_hex(&self) -> Option { self.ignore_hex } + + fn identifier_include_digits(&self) -> Option { + self.identifier_include_digits + } + + fn identifier_include_chars(&self) -> Option<&str> { + self.identifier_include_chars.as_ref().map(|s| s.as_str()) + } } fn find_project_file(dir: std::path::PathBuf, name: &str) -> Option { diff --git a/src/main.rs b/src/main.rs index e655e7b..319858c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -314,6 +314,8 @@ fn run() -> Result { let parser = typos::tokens::ParserBuilder::new() .ignore_hex(config.default.ignore_hex()) + .include_digits(config.default.identifier_include_digits()) + .include_chars(config.default.identifier_include_chars().to_owned()) .build(); let checks = typos::checks::CheckSettings::new()