Skip to content

Commit bc1b159

Browse files
committed
Add shellcheck and fix issues
1 parent 645f3fd commit bc1b159

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
run: |
2222
curl -L "$(curl -s https://api.github.com/repos/mvdan/sh/releases/latest | grep -o -E -m 1 "https://.+?linux_amd64")" > shfmt \
2323
&& chmod +x shfmt && sudo mv shfmt /usr/bin/
24+
25+
- name: Install shellcheck
26+
run: |
27+
sudo apt update && sudo apt install shellcheck
2428
# Need to success pre-commit fix push
2529
- uses: actions/checkout@v2
2630
with:

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ repos:
3333
hooks:
3434
- id: shfmt
3535
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
36+
- id: shellcheck

infracost_breakdown.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function common::parse_cmdline {
6262
;;
6363
--)
6464
shift
65+
# shellcheck disable=SC2034 # Common function
6566
FILES=("$@")
6667
break
6768
;;
@@ -101,6 +102,7 @@ function infracost_breakdown_ {
101102
# $hook_config receives string like '1 > 2; 3 == 4;' etc.
102103
# It gets split by `;` into array, which we're parsing here ('1 > 2' ' 3 == 4')
103104
# Next line removes leading spaces, just for fancy output reason.
105+
# shellcheck disable=SC2001 # Rule exception
104106
check=$(echo "$check" | sed 's/^[[:space:]]*//')
105107

106108
# Drop quotes in hook args section. From:
@@ -116,7 +118,7 @@ function infracost_breakdown_ {
116118
}; then
117119
check="${check:1:-1}"
118120
fi
119-
121+
# shellcheck disable=SC2207 # Can't found working `read` command
120122
operations=($(echo "$check" | grep -oE '[!<>=]{1,2}'))
121123
# Get the very last operator, that is used in comparison inside `jq` query.
122124
# From the example below we need to pick the `>` which is in between `add` and `1000`,

terraform_docs.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ function terraform_docs {
121121
local add_to_existing=false
122122
local create_if_not_exist=false
123123

124-
configs=($hook_config)
124+
read -r -a configs <<< "$hook_config"
125+
125126
for c in "${configs[@]}"; do
126-
config=(${c//=/ })
127+
128+
IFS="=" read -r -a config <<< "$c"
127129
key=${config[0]}
128130
value=${config[1]}
129131

@@ -161,9 +163,11 @@ function terraform_docs {
161163
dir="$(dirname "$text_file")"
162164

163165
mkdir -p "$dir"
164-
echo -e "# ${PWD##*/}\n" >> "$text_file"
165-
echo "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" >> "$text_file"
166-
echo "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" >> "$text_file"
166+
{
167+
echo -e "# ${PWD##*/}\n" >> "$text_file"
168+
echo "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
169+
echo "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->"
170+
} >> "$text_file"
167171
fi
168172

169173
# If file still not exist - skip dir

tests/hooks_performance_test.sh

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,33 @@ function generate_table {
4444
| time command | max | min | mean | median |
4545
| -------------- | ------ | ------ | -------- | ------ |
4646
| users seconds | $(
47-
printf %"s\n" $users_seconds | datamash max 1
47+
printf %"s\n" "$users_seconds" | datamash max 1
4848
) | $(
49-
printf %"s\n" $users_seconds | datamash min 1
49+
printf %"s\n" "$users_seconds" | datamash min 1
5050
) | $(
51-
printf %"s\n" $users_seconds | datamash mean 1
52-
) | $(printf %"s\n" $users_seconds | datamash median 1) |
51+
printf %"s\n" "$users_seconds" | datamash mean 1
52+
) | $(printf %"s\n" "$users_seconds" | datamash median 1) |
5353
| system seconds | $(
54-
printf %"s\n" $system_seconds | datamash max 1
54+
printf %"s\n" "$system_seconds" | datamash max 1
5555
) | $(
56-
printf %"s\n" $system_seconds | datamash min 1
56+
printf %"s\n" "$system_seconds" | datamash min 1
5757
) | $(
58-
printf %"s\n" $system_seconds | datamash mean 1
59-
) | $(printf %"s\n" $system_seconds | datamash median 1) |
58+
printf %"s\n" "$system_seconds" | datamash mean 1
59+
) | $(printf %"s\n" "$system_seconds" | datamash median 1) |
6060
| CPU % | $(
61-
printf %"s\n" $cpu | datamash max 1
61+
printf %"s\n" "$cpu" | datamash max 1
6262
) | $(
63-
printf %"s\n" $cpu | datamash min 1
63+
printf %"s\n" "$cpu" | datamash min 1
6464
) | $(
65-
printf %"s\n" $cpu | datamash mean 1
66-
) | $(printf %"s\n" $cpu | datamash median 1) |
65+
printf %"s\n" "$cpu" | datamash mean 1
66+
) | $(printf %"s\n" "$cpu" | datamash median 1) |
6767
| Total time | $(
68-
printf %"s\n" $total_time | datamash max 1
68+
printf %"s\n" "$total_time" | datamash max 1
6969
) | $(
70-
printf %"s\n" $total_time | datamash min 1
70+
printf %"s\n" "$total_time" | datamash min 1
7171
) | $(
72-
printf %"s\n" $total_time | datamash mean 1
73-
) | $(printf %"s\n" $total_time | datamash median 1) |
72+
printf %"s\n" "$total_time" | datamash mean 1
73+
) | $(printf %"s\n" "$total_time" | datamash median 1) |
7474
"
7575
}
7676

@@ -82,8 +82,7 @@ function save_result {
8282

8383
local FILE_NAME=${5:-"tests_result.md"}
8484

85-
echo -e "\n$DESCRIPTION" >> "tests/results/$FILE_NAME"
86-
echo -e "$TABLE" >> "tests/results/$FILE_NAME"
85+
echo -e "\n$DESCRIPTION\n$TABLE" >> "tests/results/$FILE_NAME"
8786
# shellcheck disable=SC2016,SC2128 # Irrelevant
8887
echo -e '
8988
<details><summary>Run details</summary>

0 commit comments

Comments
 (0)