Skip to content

Commit e582ef5

Browse files
authored
Merge pull request sstephenson#242 from AlexSkrypnyk/feature/fix-coding-standards
Fixed coding standards in shell scripts and enabled shellcheck exit code in CI.
2 parents 1c83a1b + 118391d commit e582ef5

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ script:
3030
- |
3131
if [[ "${TRAVIS_OS_NAME:-}" == 'linux' ]]; then
3232
# @todo: Remove "|| true" once all coding standards issues are fixed.
33-
./shellcheck.sh || true
33+
./shellcheck.sh
3434
fi
3535
3636
if [[ "${TRAVIS_OS_NAME:-}" == 'linux' && -n "${BASHVER}" ]]; then

libexec/bats-core/bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ expand_path() {
6060
printf -v "$result" '%s/%s' "$dirname" "${path##*/}"
6161
}
6262

63-
BATS_LIBEXEC="$(dirname "$(expand_link "$BASH_SOURCE")")"
63+
BATS_LIBEXEC="$(dirname "$(expand_link "${BASH_SOURCE[0]}")")"
6464
export BATS_CWD="$PWD"
6565
export BATS_TEST_PATTERN="^[[:blank:]]*@test[[:blank:]]+(.*[^[:blank:]])[[:blank:]]+\{(.*)\$"
6666
export BATS_TEST_FILTER=

libexec/bats-core/bats-exec-suite

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ while [[ "$#" -ne 0 ]]; do
2323
num_jobs="$1"
2424
;;
2525
-x)
26+
# shellcheck disable=SC2034
2627
extended_syntax_flag='-x'
2728
flags+=('-x')
2829
;;
@@ -34,6 +35,7 @@ while [[ "$#" -ne 0 ]]; do
3435
done
3536

3637
if ( type -p parallel &>/dev/null ); then
38+
# shellcheck disable=SC2034
3739
have_gnu_parallel=1
3840
elif [[ "$num_jobs" != 1 ]]; then
3941
printf 'bats: cannot execute "%s" jobs without GNU parallel\n' "$num_jobs" >&2

libexec/bats-core/bats-exec-test

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#!/usr/bin/env bash
22
set -eET
33

4+
# Variables used in other scripts.
45
BATS_COUNT_ONLY=''
56
BATS_TEST_FILTER=''
67
BATS_EXTENDED_SYNTAX=''
78

89
while [[ "$#" -ne 0 ]]; do
910
case "$1" in
1011
-c)
12+
# shellcheck disable=SC2034
1113
BATS_COUNT_ONLY=1
1214
;;
1315
-f)
1416
shift
17+
# shellcheck disable=SC2034
1518
BATS_TEST_FILTER="$1"
1619
;;
1720
-x)
@@ -52,15 +55,21 @@ load() {
5255
exit 1
5356
fi
5457

58+
# Dynamically loaded user files provided outside of Bats.
59+
# shellcheck disable=SC1090
5560
source "${filename}"
5661
}
5762

5863
run() {
5964
local origFlags="$-"
6065
set +eET
6166
local origIFS="$IFS"
67+
# 'output', 'status', 'lines' are global variables available to tests.
68+
# shellcheck disable=SC2034
6269
output="$("$@" 2>&1)"
70+
# shellcheck disable=SC2034
6371
status="$?"
72+
# shellcheck disable=SC2034,SC2206
6473
IFS=$'\n' lines=($output)
6574
IFS="$origIFS"
6675
set "-$origFlags"
@@ -211,7 +220,7 @@ bats_trim_filename() {
211220
}
212221

213222
bats_debug_trap() {
214-
if [[ "$BASH_SOURCE" != "$1" ]]; then
223+
if [[ "${BASH_SOURCE[0]}" != "$1" ]]; then
215224
# The last entry in the stack trace is not useful when en error occured:
216225
# It is either duplicated (kinda correct) or has wrong line number (Bash < 4.4)
217226
# Therefore we capture the stacktrace but use it only after the next debug
@@ -365,6 +374,8 @@ bats_evaluate_preprocessed_source() {
365374
if [[ -z "$BATS_TEST_SOURCE" ]]; then
366375
BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src"
367376
fi
377+
# Dynamically loaded user files provided outside of Bats.
378+
# shellcheck disable=SC1090
368379
source "$BATS_TEST_SOURCE"
369380
}
370381

libexec/bats-core/bats-format-tap-stream

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ fi
2020

2121
update_screen_width() {
2222
screen_width="$(tput cols)"
23-
count_column_left=$(( $screen_width - $count_column_width ))
23+
count_column_left=$(( screen_width - count_column_width ))
2424
}
2525

2626
trap update_screen_width WINCH
2727
update_screen_width
2828

2929
begin() {
3030
go_to_column 0
31-
buffer_with_truncation $(( $count_column_left - 1 )) ' %s' "$name"
31+
buffer_with_truncation $(( count_column_left - 1 )) ' %s' "$name"
3232
clear_to_end_of_line
3333
go_to_column $count_column_left
3434
buffer "%${#count}s/${count}" "$index"
@@ -92,18 +92,19 @@ buffer_with_truncation() {
9292
shift
9393
local string
9494

95+
# shellcheck disable=SC2059
9596
printf -v 'string' -- "$@"
9697

9798
if [[ "${#string}" -gt "$width" ]]; then
98-
buffer '%s...' "${string:0:$(( $width - 4 ))}"
99+
buffer '%s...' "${string:0:$(( width - 4 ))}"
99100
else
100101
buffer '%s' "$string"
101102
fi
102103
}
103104

104105
go_to_column() {
105106
local column="$1"
106-
buffer '\x1B[%dG' $(( $column + 1 ))
107+
buffer '\x1B[%dG' $(( column + 1 ))
107108
}
108109

109110
clear_to_end_of_line() {
@@ -123,7 +124,7 @@ set_color() {
123124
if [[ "$2" == 'bold' ]]; then
124125
weight=1
125126
fi
126-
buffer '\x1B[%d;%dm' "$(( 30 + $color ))" "$weight"
127+
buffer '\x1B[%d;%dm' "$(( 30 + color ))" "$weight"
127128
}
128129

129130
clear_color() {
@@ -134,6 +135,7 @@ _buffer=
134135

135136
buffer() {
136137
local content
138+
# shellcheck disable=SC2059
137139
printf -v content -- "$@"
138140
_buffer+="$content"
139141
}

libexec/bats-core/bats-preprocess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tests=()
4242
name="${name%[\'\"]}"
4343
body="${BASH_REMATCH[2]}"
4444
bats_encode_test_name "$name" 'encoded_name'
45-
printf '%s() { bats_test_begin "%s"; %s\n' "$encoded_name" "$name" "$body" || :
45+
printf '%s() { bats_test_begin "%s"; %s\n' "${encoded_name:?}" "$name" "$body" || :
4646

4747
if [[ -z "$BATS_TEST_FILTER" || "$name" =~ $BATS_TEST_FILTER ]]; then
4848
tests+=("$encoded_name")

0 commit comments

Comments
 (0)