mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-09 20:23:35 +01:00
lint: Find function calls in default arguments
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user