4 # Copyright (c) 2020 Project CHIP Authors
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
21 # Run shellcheck on all the shell-ish files in the tree
22 patterns=('*.bash*' 'bash*'
26 '.zlogout*' 'zlogout*'
27 '.zprofile*' 'zprofile*'
28 '*.sh' '.shlib*' 'shlib*'
29 '.profile*' 'profile*'
32 # excluding these directories (e.g. third_party/* )
35 # shellcheck disable=SC1091
36 [[ -f .shellcheck_tree ]] && . .shellcheck_tree
38 [[ ${*/--help//} != "${*}" ]] && {
39 echo "Usage: $me <OPTIONS>
41 Shellcheck all scripts in the tree.
44 --git shellcheck via git ls-files, default is 'find .'
45 --help get this message
51 if [[ ${*/--git//} != "${*}" ]]; then
53 # To run on git-files only
55 git ls-files -- "${patterns[@]}" | while read -r file; do
56 for exclude in "${excludes[@]}"; do
57 [[ $file =~ $exclude ]] && continue 2
59 shellcheck -f gcc "$file"
66 for exclude in "${excludes[@]}"; do
67 exclude_args+=('!' -path "./$exclude" -a)
71 for pattern in "${patterns[@]}"; do
72 pattern_args+=(-o -name "$pattern")
75 find . "${exclude_args[@]}" '(' "${pattern_args[@]:1}" ')' -type f -exec shellcheck -f gcc {} +