lint: Call lint_commit_msg from test_runner

Allowing to call the check from the test_runner allows for consistent
error messages. Also, manually setting the commit range is no longer
needed.
This commit is contained in:
MarcoFalke
2025-01-14 14:05:18 +01:00
parent fa99728b0c
commit faf8fc5487
2 changed files with 41 additions and 52 deletions

View File

@@ -73,6 +73,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
name: "scripted_diff",
lint_fn: lint_scripted_diff
},
&Linter {
description: "Check that commit messages have a new line before the body or no body at all.",
name: "commit_msg",
lint_fn: lint_commit_msg
},
&Linter {
description: "Check that tabs are not used as whitespace",
name: "tabs_whitespace",
@@ -243,6 +248,42 @@ fn lint_scripted_diff() -> LintResult {
}
}
fn lint_commit_msg() -> LintResult {
let mut good = true;
let commit_hashes = check_output(git().args(&[
"-c",
"log.showSignature=false",
"log",
&commit_range(),
"--format=%H",
]))?;
for hash in commit_hashes.lines() {
let commit_info = check_output(git().args([
"-c",
"log.showSignature=false",
"log",
"--format=%B",
"-n",
"1",
hash,
]))?;
if let Some(line) = commit_info.lines().nth(1) {
if !line.is_empty() {
println!(
"The subject line of commit hash {} is followed by a non-empty line. Subject lines should always be followed by a blank line.",
hash
);
good = false;
}
}
}
if good {
Ok(())
} else {
Err("".to_string())
}
}
fn lint_py_lint() -> LintResult {
let bin_name = "ruff";
let checks = format!(