diff --git a/crates/typos-cli/src/config.rs b/crates/typos-cli/src/config.rs index 5e30f7f..34a1994 100644 --- a/crates/typos-cli/src/config.rs +++ b/crates/typos-cli/src/config.rs @@ -4,8 +4,16 @@ use kstring::KString; use crate::file_type_specifics; -pub const SUPPORTED_FILE_NAMES: &[&str] = - &["typos.toml", "_typos.toml", ".typos.toml", "pyproject.toml"]; +pub const SUPPORTED_FILE_NAMES: &[&str] = &[ + "typos.toml", + "_typos.toml", + ".typos.toml", + CARGO_TOML, + PYPROJECT_TOML, +]; + +const CARGO_TOML: &str = "Cargo.toml"; +const PYPROJECT_TOML: &str = "pyproject.toml"; #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] @@ -20,6 +28,28 @@ pub struct Config { pub overrides: EngineConfig, } +#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(default)] +#[serde(rename_all = "kebab-case")] +pub struct CargoTomlConfig { + pub workspace: Option, + pub package: Option, +} + +#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(default)] +#[serde(rename_all = "kebab-case")] +pub struct CargoTomlPackage { + pub metadata: CargoTomlMetadata, +} + +#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(default)] +#[serde(rename_all = "kebab-case")] +pub struct CargoTomlMetadata { + pub typos: Option, +} + #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(default)] #[serde(rename_all = "kebab-case")] @@ -55,15 +85,31 @@ impl Config { ) })?; - if path.file_name().unwrap() == "pyproject.toml" { - let config = toml::from_str::(&s)?; + if path.file_name().unwrap() == CARGO_TOML { + let config = toml::from_str::(&s)?; + let typos = config + .workspace + .and_then(|w| w.metadata.typos) + .or(config.package.and_then(|p| p.metadata.typos)); - if config.tool.typos.is_none() { - log::debug!("No `tool.typos` section found in `pyproject.toml`, skipping"); + if let Some(typos) = typos { + Ok(Some(typos)) + } else { + log::debug!( + "No `package.metadata.typos` section found in `{CARGO_TOML}`, skipping" + ); Ok(None) + } + } else if path.file_name().unwrap() == PYPROJECT_TOML { + let config = toml::from_str::(&s)?; + + if let Some(typos) = config.tool.typos { + Ok(Some(typos)) } else { - Ok(config.tool.typos) + log::debug!("No `tool.typos` section found in `{PYPROJECT_TOML}`, skipping"); + + Ok(None) } } else { Self::from_toml(&s).map(Some)