Skip to content

Commit 9cd9097

Browse files
committed
tidy: warn when --extra-checks is passed an invalid lang:kind combo
1 parent 5a88fb1 commit 9cd9097

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const RUFF_CONFIG_PATH: &[&str] = &["src", "tools", "tidy", "config", "ruff.toml
3939
const RUFF_CACHE_PATH: &[&str] = &["cache", "ruff_cache"];
4040
const PIP_REQ_PATH: &[&str] = &["src", "tools", "tidy", "config", "requirements.txt"];
4141

42+
// this must be kept in sync with with .github/workflows/spellcheck.yml
4243
const SPELLCHECK_DIRS: &[&str] = &["compiler", "library", "src/bootstrap", "src/librustdoc"];
4344

4445
pub fn check(
@@ -87,6 +88,7 @@ fn check_impl(
8788
}
8889
}
8990
Err(err) => {
91+
// only warn because before bad extra checks would be silently ignored.
9092
eprintln!("warning: bad extra check argument {src:?}: {err:?}");
9193
None
9294
}
@@ -260,7 +262,6 @@ fn check_impl(
260262

261263
if spellcheck {
262264
let config_path = root_path.join("typos.toml");
263-
// sync target files with .github/workflows/spellcheck.yml
264265
let mut args = vec!["-c", config_path.as_os_str().to_str().unwrap()];
265266

266267
args.extend_from_slice(SPELLCHECK_DIRS);
@@ -666,6 +667,7 @@ enum ExtraCheckParseError {
666667
UnknownKind(String),
667668
#[allow(dead_code)]
668669
UnknownLang(String),
670+
UnsupportedKindForLang,
669671
/// Too many `:`
670672
TooManyParts,
671673
/// Tried to parse the empty string
@@ -703,6 +705,21 @@ impl ExtraCheckArg {
703705
};
704706
!crate::files_modified(ci_info, |s| s.ends_with(ext))
705707
}
708+
709+
fn has_supported_kind(&self) -> bool {
710+
let Some(kind) = self.kind else {
711+
// "run all extra checks" mode is supported for all languages.
712+
return true;
713+
};
714+
use ExtraCheckKind::*;
715+
let supported_kinds: &[_] = match self.lang {
716+
ExtraCheckLang::Py => &[Fmt, Lint],
717+
ExtraCheckLang::Cpp => &[Fmt],
718+
ExtraCheckLang::Shell => &[Lint],
719+
ExtraCheckLang::Spellcheck => &[],
720+
};
721+
supported_kinds.contains(&kind)
722+
}
706723
}
707724

708725
impl FromStr for ExtraCheckArg {
@@ -725,7 +742,12 @@ impl FromStr for ExtraCheckArg {
725742
if parts.next().is_some() {
726743
return Err(ExtraCheckParseError::TooManyParts);
727744
}
728-
Ok(Self { auto, lang: first.parse()?, kind: second.map(|s| s.parse()).transpose()? })
745+
let arg = Self { auto, lang: first.parse()?, kind: second.map(|s| s.parse()).transpose()? };
746+
if !arg.has_supported_kind() {
747+
return Err(ExtraCheckParseError::UnsupportedKindForLang);
748+
}
749+
750+
Ok(arg)
729751
}
730752
}
731753

0 commit comments

Comments
 (0)