-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathshellcheck
More file actions
executable file
·85 lines (74 loc) · 2.5 KB
/
shellcheck
File metadata and controls
executable file
·85 lines (74 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Summary: execute shellcheck for all shell scripts in this repository
#
# Usage:
# check/shellcheck [--dry-run] [shellcheck-arguments]
#
# Use the '--dry-run' option to print out the shellcheck command line without
# running it. This displays all shell script files found in the repository.
set -euo pipefail
# Change working directory to the repository root.
thisdir=$(dirname "${BASH_SOURCE[0]:?}")
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel)
cd "${repo_dir}"
# Process command line arguments
opt_dry_run=0
declare -a shellcheck_options
declare -a our_shell_scripts
for arg in "$@"; do
if [[ "${arg}" == "--dry-run" ]]; then
opt_dry_run=1
else
shellcheck_options+=( "${arg}" )
fi
done
# Find all shell scripts in this repository.
IFS=$'\n' read -r -d "" -a our_shell_scripts < <(
git ls-files -z -- \
':(exclude)*.'{hdf5,ipynb,json,md,py,rst,toml,ts,txt,yaml} |
xargs -0 file | grep -i 'shell script' | cut -d: -f1;
printf "\0"
)
# Verify our_shell_scripts array - require it must contain files below.
declare -a required_shell_scripts
required_shell_scripts=(
# items below must be sorted
check/all
check/format-incremental
check/mypy
check/nbformat
check/pylint
check/pylint-changed-files
check/pytest
check/pytest-and-incremental-coverage
)
scripts_not_found=$(comm -13 \
<(printf "%s\n" "${our_shell_scripts[@]}") \
<(printf "%s\n" "${required_shell_scripts[@]}") )
if [[ -n "${scripts_not_found}" ]]; then
echo "Identification of shell scripts failed - files not found:" >&2
printf "\n%s\n\n" "${scripts_not_found}" >&2
echo "Please fix $0." >&2
exit 2
fi
# Ready to run here.
if (( opt_dry_run )); then
printf '%s ' '>>' 'shellcheck' "${shellcheck_options[@]}"
printf '\\\n %s ' "${our_shell_scripts[@]}"
printf '\\\n;\n'
else
shellcheck "${shellcheck_options[@]}" "${our_shell_scripts[@]}"
fi