Skip to content

Commit fac7b7f

Browse files
author
MarcoFalke
committed
lint: Find function calls in default arguments
1 parent df24197 commit fac7b7f

File tree

3 files changed

+35
-72
lines changed

3 files changed

+35
-72
lines changed

ci/lint/04_install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ${CI_RETRY_EXE} pip3 install \
5353
lief==0.13.2 \
5454
mypy==1.4.1 \
5555
pyzmq==25.1.0 \
56+
ruff==0.5.5 \
5657
vulture==2.6
5758

5859
SHELLCHECK_VERSION=v0.8.0

test/lint/lint-python-mutable-default-parameters.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

test/lint/test_runner/src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
3535
name: "markdown",
3636
lint_fn: lint_markdown
3737
},
38+
&Linter {
39+
description: "Check the default arguments in python",
40+
name: "py_mut_arg_default",
41+
lint_fn: lint_py_mut_arg_default,
42+
},
3843
&Linter {
3944
description: "Check that std::filesystem is not used directly",
4045
name: "std_filesystem",
@@ -180,6 +185,35 @@ fn lint_subtree() -> LintResult {
180185
}
181186
}
182187

188+
fn lint_py_mut_arg_default() -> LintResult {
189+
let bin_name = "ruff";
190+
let checks = ["B006", "B008"]
191+
.iter()
192+
.map(|c| format!("--select={}", c))
193+
.collect::<Vec<_>>();
194+
let files = check_output(
195+
git()
196+
.args(["ls-files", "--", "*.py"])
197+
.args(get_pathspecs_exclude_subtrees()),
198+
)?;
199+
200+
let mut cmd = Command::new(bin_name);
201+
cmd.arg("check").args(checks).args(files.lines());
202+
203+
match cmd.status() {
204+
Ok(status) if status.success() => Ok(()),
205+
Ok(_) => Err(format!("`{}` found errors!", bin_name)),
206+
Err(e) if e.kind() == ErrorKind::NotFound => {
207+
println!(
208+
"`{}` was not found in $PATH, skipping those checks.",
209+
bin_name
210+
);
211+
Ok(())
212+
}
213+
Err(e) => Err(format!("Error running `{}`: {}", bin_name, e)),
214+
}
215+
}
216+
183217
fn lint_std_filesystem() -> LintResult {
184218
let found = git()
185219
.args([

0 commit comments

Comments
 (0)