Skip to content

Commit a870be7

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

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ fn check_impl(
8787
}
8888
}
8989
Err(err) => {
90+
// only warn becasue before bad extra checks would be silently ignored.
9091
eprintln!("warning: bad extra check argument {src:?}: {err:?}");
9192
None
9293
}
@@ -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)