pub fn check_id_from_name(name: &str) -> String {
match name.to_ascii_lowercase().as_str() {
"typescript" => "tsc".to_string(),
"cargo check" => "cargo".to_string(),
"clippy" => "clippy".to_string(),
"rustfmt" => "rustfmt".to_string(),
"cargo test" => "cargo_test".to_string(),
"cargo audit" => "cargo_audit".to_string(),
"cargo geiger" => "cargo_geiger".to_string(),
"eslint" => "eslint".to_string(),
"stylelint" => "stylelint".to_string(),
"vitest" => "tests".to_string(),
"ruff" => "ruff".to_string(),
"mypy" => "mypy".to_string(),
"pytest" => "pytest".to_string(),
other => other.replace([' ', '-', '/'], "_"),
}
}
#[cfg(test)]
mod tests {
use super::check_id_from_name;
#[test]
fn check_id_mapping_snapshot() {
let cases = [
("typescript", "tsc"),
("TypeScript", "tsc"),
("cargo check", "cargo"),
("clippy", "clippy"),
("rustfmt", "rustfmt"),
("cargo test", "cargo_test"),
("cargo audit", "cargo_audit"),
("cargo geiger", "cargo_geiger"),
("eslint", "eslint"),
("stylelint", "stylelint"),
("vitest", "tests"),
("ruff", "ruff"),
("mypy", "mypy"),
("Mypy", "mypy"),
("pytest", "pytest"),
("semgrep scan", "semgrep_scan"),
("heuristics_loctree", "heuristics_loctree"),
("Some-Weird/Name", "some_weird_name"),
];
for (name, expected) in cases {
assert_eq!(
check_id_from_name(name),
expected,
"check_id drift for {name:?}"
);
}
}
}