Skip to content

Commit ebdd5d3

Browse files
committed
tidy: warn when --extra-checks is passed an invalid lang:kind combo
1 parent 9887e63 commit ebdd5d3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ fn check_impl(
8080
}
8181
}
8282
Err(err) => {
83+
// only warn becasue before bad extra checks would be silently ignored.
8384
eprintln!("warning: bad extra check argument {src:?}: {err:?}");
8485
None
8586
}
@@ -612,6 +613,7 @@ enum ExtraCheckParseError {
612613
UnknownKind(String),
613614
#[allow(dead_code)]
614615
UnknownLang(String),
616+
UnsupportedKindForLang,
615617
/// Too many `:`
616618
TooManyParts,
617619
/// Tried to parse the empty string
@@ -644,6 +646,20 @@ impl ExtraCheckArg {
644646
};
645647
!crate::files_modified(ci_info, |s| s.ends_with(ext))
646648
}
649+
650+
fn has_supported_kind(&self) -> bool {
651+
let Some(kind) = self.kind else {
652+
// "run all extra checks" mode is supported for all languages.
653+
return true;
654+
};
655+
use ExtraCheckKind::*;
656+
let supported_kinds: &[_] = match self.lang {
657+
ExtraCheckLang::Py => &[Fmt, Lint],
658+
ExtraCheckLang::Cpp => &[Fmt],
659+
ExtraCheckLang::Shell => &[Lint],
660+
};
661+
supported_kinds.contains(&kind)
662+
}
647663
}
648664

649665
impl FromStr for ExtraCheckArg {
@@ -666,7 +682,12 @@ impl FromStr for ExtraCheckArg {
666682
if parts.next().is_some() {
667683
return Err(ExtraCheckParseError::TooManyParts);
668684
}
669-
Ok(Self { auto, lang: first.parse()?, kind: second.map(|s| s.parse()).transpose()? })
685+
let arg = Self { auto, lang: first.parse()?, kind: second.map(|s| s.parse()).transpose()? };
686+
if !arg.has_supported_kind() {
687+
return Err(ExtraCheckParseError::UnsupportedKindForLang);
688+
}
689+
690+
Ok(arg)
670691
}
671692
}
672693

0 commit comments

Comments
 (0)