Skip to content

Commit c1d84c3

Browse files
authored
Merge pull request #9 from chainguard-dev/shellcheck-passthrough-args
shellcheck_run_steps: Allow passing arguments through to shellcheck
2 parents 9b89272 + e03541c commit c1d84c3

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ repos:
3434
hooks:
3535
- id: pyupgrade
3636
args: [--py39-plus]
37-
- repo: https://github.com/hhatto/autopep8
38-
rev: 4046ad49e25b7fa1db275bf66b1b7d60600ac391 # frozen: v2.3.2
39-
hooks:
40-
- id: autopep8
41-
- repo: https://github.com/PyCQA/flake8
42-
rev: 4b5e89b4b108a6c1a000c591d334a99a80d34c7b # frozen: 7.2.0
43-
hooks:
44-
- id: flake8
4537
- repo: https://github.com/pre-commit/mirrors-mypy
4638
rev: f40886d54c729f533f864ed6ce584e920feb0af7 # frozen: v1.15.0
4739
hooks:

pre_commit_hooks/shellcheck_run_steps.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
def do_shellcheck(
1818
melange_cfg: Mapping[str, Any],
1919
shellcheck: list[str],
20+
shellcheck_args: list[str],
2021
) -> None:
2122
if melange_cfg == {}:
2223
return
@@ -48,11 +49,14 @@ def do_shellcheck(
4849
),
4950
),
5051
)
52+
if len(all_steps) == 0:
53+
return
5154
for step, shfile in all_steps:
5255
shfile.write(step["runs"])
5356
shfile.close()
5457
subprocess.check_call(
5558
["/usr/bin/shellcheck"]
59+
+ shellcheck_args
5660
+ ["--shell=busybox", "--"]
5761
+ [os.path.basename(f.name) for _, f in all_steps],
5862
cwd=os.getcwd(),
@@ -61,7 +65,12 @@ def do_shellcheck(
6165

6266
def main(argv: Sequence[str] | None = None) -> int:
6367
parser = argparse.ArgumentParser()
64-
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
68+
parser.add_argument(
69+
"filenames",
70+
nargs="*",
71+
help="Filenames to check. You can also pass "
72+
"arguments to shellcheck before a '--' separator.",
73+
)
6574
parser.add_argument(
6675
"--shellcheck",
6776
default=[
@@ -76,9 +85,16 @@ def main(argv: Sequence[str] | None = None) -> int:
7685
help="shellcheck command",
7786
)
7887
args = parser.parse_args(argv)
88+
try:
89+
idx = args.filenames.index("--")
90+
shellcheck_args = args.filenames[:idx]
91+
filenames = args.filenames[idx + 1 :]
92+
except ValueError:
93+
shellcheck_args = []
94+
filenames = args.filenames
7995

8096
melange_cfg = {}
81-
for filename in args.filenames:
97+
for filename in filenames:
8298
with tempfile.NamedTemporaryFile(
8399
"w",
84100
delete_on_close=False,
@@ -97,7 +113,11 @@ def main(argv: Sequence[str] | None = None) -> int:
97113
try:
98114
with open(compiled_out.name) as compiled_in:
99115
melange_cfg = yaml.load(compiled_in)
100-
do_shellcheck(melange_cfg, args.shellcheck)
116+
do_shellcheck(
117+
melange_cfg,
118+
args.shellcheck,
119+
shellcheck_args,
120+
)
101121
except ruamel.yaml.YAMLError as exc:
102122
print(exc)
103123
return 1

0 commit comments

Comments
 (0)