lint: Find function calls in default arguments

This commit is contained in:
MarcoFalke
2024-07-31 08:33:01 +02:00
parent df241970a3
commit fac7b7ff7f
3 changed files with 35 additions and 72 deletions

View File

@@ -35,6 +35,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
name: "markdown",
lint_fn: lint_markdown
},
&Linter {
description: "Check the default arguments in python",
name: "py_mut_arg_default",
lint_fn: lint_py_mut_arg_default,
},
&Linter {
description: "Check that std::filesystem is not used directly",
name: "std_filesystem",
@@ -180,6 +185,35 @@ fn lint_subtree() -> LintResult {
}
}
fn lint_py_mut_arg_default() -> LintResult {
let bin_name = "ruff";
let checks = ["B006", "B008"]
.iter()
.map(|c| format!("--select={}", c))
.collect::<Vec<_>>();
let files = check_output(
git()
.args(["ls-files", "--", "*.py"])
.args(get_pathspecs_exclude_subtrees()),
)?;
let mut cmd = Command::new(bin_name);
cmd.arg("check").args(checks).args(files.lines());
match cmd.status() {
Ok(status) if status.success() => Ok(()),
Ok(_) => Err(format!("`{}` found errors!", bin_name)),
Err(e) if e.kind() == ErrorKind::NotFound => {
println!(
"`{}` was not found in $PATH, skipping those checks.",
bin_name
);
Ok(())
}
Err(e) => Err(format!("Error running `{}`: {}", bin_name, e)),
}
}
fn lint_std_filesystem() -> LintResult {
let found = git()
.args([