mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 02:20:58 -05:00
parent
95f556a918
commit
d5453cc46c
1 changed files with 47 additions and 3 deletions
|
@ -4,9 +4,15 @@ use kstring::KString;
|
||||||
|
|
||||||
use crate::file_type_specifics;
|
use crate::file_type_specifics;
|
||||||
|
|
||||||
pub const SUPPORTED_FILE_NAMES: &[&str] =
|
pub const SUPPORTED_FILE_NAMES: &[&str] = &[
|
||||||
&["typos.toml", "_typos.toml", ".typos.toml", PYPROJECT_TOML];
|
"typos.toml",
|
||||||
|
"_typos.toml",
|
||||||
|
".typos.toml",
|
||||||
|
CARGO_TOML,
|
||||||
|
PYPROJECT_TOML,
|
||||||
|
];
|
||||||
|
|
||||||
|
const CARGO_TOML: &str = "Cargo.toml";
|
||||||
const PYPROJECT_TOML: &str = "pyproject.toml";
|
const PYPROJECT_TOML: &str = "pyproject.toml";
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -22,6 +28,28 @@ pub struct Config {
|
||||||
pub overrides: EngineConfig,
|
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<CargoTomlPackage>,
|
||||||
|
pub package: Option<CargoTomlPackage>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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<Config>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
@ -57,7 +85,23 @@ impl Config {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if path.file_name().unwrap() == PYPROJECT_TOML {
|
if path.file_name().unwrap() == CARGO_TOML {
|
||||||
|
let config = toml::from_str::<CargoTomlConfig>(&s)?;
|
||||||
|
let typos = config
|
||||||
|
.workspace
|
||||||
|
.and_then(|w| w.metadata.typos)
|
||||||
|
.or(config.package.and_then(|p| p.metadata.typos));
|
||||||
|
|
||||||
|
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::<PyprojectTomlConfig>(&s)?;
|
let config = toml::from_str::<PyprojectTomlConfig>(&s)?;
|
||||||
|
|
||||||
if let Some(typos) = config.tool.typos {
|
if let Some(typos) = config.tool.typos {
|
||||||
|
|
Loading…
Reference in a new issue