Skip to content

Commit b70364a

Browse files
committed
format.sh: run shellcheck on all shell scripts
This runs the `shellcheck` linter against all shell scripts in the repo. Download the tool automatically if it's not found, at least on Linux+x86_64. Also run shellcheck in CI. Signed-off-by: Russell Bryant <[email protected]>
1 parent 9d43afc commit b70364a

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

.github/workflows/shellcheck.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Lint shell scripts
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
paths:
7+
- '**/*.sh'
8+
- '.github/workflows/shellcheck.yml'
9+
pull_request:
10+
branches:
11+
- "main"
12+
paths:
13+
- '**/*.sh'
14+
- '.github/workflows/shellcheck.yml'
15+
16+
env:
17+
LC_ALL: en_US.UTF-8
18+
19+
defaults:
20+
run:
21+
shell: bash
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
shellcheck:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: "Checkout"
31+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
32+
with:
33+
fetch-depth: 0
34+
35+
- name: "Check shell scripts"
36+
run: |
37+
tools/shellcheck.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,4 @@ benchmarks/*.json
202202

203203
# Linting
204204
actionlint
205+
shellcheck*/

.shellcheckrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# rules currently disabled:
2+
#
3+
# SC1091 (info): Not following: <sourced file> was not specified as input (see shellcheck -x)
4+
# SC2004 (style): $/${} is unnecessary on arithmetic variables.
5+
# SC2129 (style): Consider using { cmd1; cmd2; } >> file instead of individual redirects.
6+
# SC2155 (warning): Declare and assign separately to avoid masking return values.
7+
# SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
8+
#
9+
disable=SC1091,SC2004,SC2129,SC2155,SC2164

format.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ echo 'vLLM actionlint:'
294294
tools/actionlint.sh -color
295295
echo 'vLLM actionlint: Done'
296296

297+
echo 'vLLM shellcheck:'
298+
tools/shellcheck.sh
299+
echo 'vLLM shellcheck: Done'
300+
297301
if ! git diff --quiet &>/dev/null; then
298302
echo
299303
echo "🔍🔍There are files changed by the format checker or by you that are not added and committed:"

tools/shellcheck.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
scversion="stable"
4+
5+
if [ -d "shellcheck-${scversion}" ]; then
6+
export PATH="$PATH:$(pwd)/shellcheck-${scversion}"
7+
fi
8+
9+
if ! [ -x "$(command -v shellcheck)" ]; then
10+
if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
11+
echo "Please install shellcheck: https://github.com/koalaman/shellcheck?tab=readme-ov-file#installing"
12+
exit 1
13+
fi
14+
15+
# automatic local install if linux x86_64
16+
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv
17+
export PATH="$PATH:$(pwd)/shellcheck-${scversion}"
18+
fi
19+
20+
find . -name "*.sh" -not -path "./.deps/*" -exec shellcheck {} +

0 commit comments

Comments
 (0)