Skip to content

Commit e560f13

Browse files
authored
Merge pull request #12 from durkode/master
Passing options to shellcheck
2 parents e9cbbd5 + 2671585 commit e560f13

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

hooks/command

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ if [[ -z ${files:-} ]] ; then
3434
exit 1
3535
fi
3636

37+
# Read in the options to pass to shellcheck
38+
mapfile -t options<<<"$(plugin_read_list OPTIONS)"
39+
3740
echo "+++ Running shellcheck on ${#files[@]} files"
38-
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" koalaman/shellcheck "${files[@]}" ; then
41+
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" koalaman/shellcheck "${options[@]+${options[@]}}" "${files[@]}" ; then
3942
echo "Files are ok ✅"
4043
else
4144
exit 1

plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ configuration:
99
files:
1010
type: [string, array]
1111
minItems: 1
12+
options:
13+
type: [string, array]
14+
minItems: 1
1215
required:
1316
- files

tests/run.bats

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,57 @@ load '/usr/local/lib/bats/load.bash'
3434
unstub docker
3535
}
3636

37+
@test "Shellcheck a single file with single option" {
38+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/subdir/llamas.sh"
39+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_0="--exclude=SC2086"
40+
41+
stub docker \
42+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck --exclude=SC2086 tests/testdata/subdir/llamas.sh : echo testing llamas.sh"
43+
44+
run "$PWD/hooks/command"
45+
46+
assert_success
47+
assert_output --partial "testing llamas.sh"
48+
49+
unstub docker
50+
}
51+
52+
@test "Shellcheck a single file with multiple options" {
53+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/subdir/llamas.sh"
54+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_0="--exclude=SC2086"
55+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_1="--format=gcc"
56+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_2="-x"
57+
58+
stub docker \
59+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck --exclude=SC2086 --format=gcc -x tests/testdata/subdir/llamas.sh : echo testing llamas.sh"
60+
61+
run "$PWD/hooks/command"
62+
63+
assert_success
64+
assert_output --partial "testing llamas.sh"
65+
66+
unstub docker
67+
}
68+
69+
@test "Shellcheck multiple files with multiple options" {
70+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
71+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_1="tests/testdata/subdir/*"
72+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_2="missing"
73+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_0="--exclude=SC2086"
74+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_1="--format=gcc"
75+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_2="-x"
76+
77+
stub docker \
78+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck --exclude=SC2086 --format=gcc -x tests/testdata/test.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell\ with\ space.sh' : echo testing test.sh"
79+
80+
run "$PWD/hooks/command"
81+
82+
assert_success
83+
assert_output --partial "testing test.sh"
84+
85+
unstub docker
86+
}
87+
3788
@test "Shellcheck failure" {
3889
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/subdir/llamas.sh"
3990

0 commit comments

Comments
 (0)