|
6 | 6 | # |
7 | 7 | # For shell files, it runs shfmt. If you don't have that installed, you can get |
8 | 8 | # it with: |
9 | | -# go get -u gopkg.in/mvdan/sh.v1/cmd/shfmt |
| 9 | +# curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 |
| 10 | +# chmod +x shfmt |
10 | 11 | # |
11 | 12 | # With no arguments, it lints the current files staged |
12 | 13 | # for git commit. Or you can pass it explicit filenames |
@@ -50,14 +51,6 @@ spell_check() { |
50 | 51 | local filename="$1" |
51 | 52 | local lint_result=0 |
52 | 53 |
|
53 | | - # we don't want to spell check tar balls, binaries, Makefile and json files |
54 | | - if file "$filename" | grep executable >/dev/null 2>&1; then |
55 | | - return $lint_result |
56 | | - fi |
57 | | - if [[ $filename == *".tar" || $filename == *".gz" || $filename == *".json" || $(basename "$filename") == "Makefile" ]]; then |
58 | | - return $lint_result |
59 | | - fi |
60 | | - |
61 | 54 | # misspell is completely optional. If you don't like it |
62 | 55 | # don't have it installed. |
63 | 56 | if ! type misspell >/dev/null 2>&1; then |
@@ -187,19 +180,24 @@ lint() { |
187 | 180 | *.pb.go) return ;; |
188 | 181 | esac |
189 | 182 |
|
190 | | - if [[ "$(file --mime-type "${filename}" | awk '{print $2}')" == "text/x-shellscript" ]]; then |
191 | | - ext="sh" |
192 | | - fi |
| 183 | + mimetype=$(file --mime-type "${filename}" | awk '{print $2}') |
193 | 184 |
|
194 | | - case "$ext" in |
195 | | - go) lint_go "${filename}" || lint_result=1 ;; |
196 | | - sh) lint_sh "${filename}" || lint_result=1 ;; |
197 | | - tf) lint_tf "${filename}" || lint_result=1 ;; |
198 | | - md) lint_md "${filename}" || lint_result=1 ;; |
199 | | - py) lint_py "${filename}" || lint_result=1 ;; |
| 185 | + case "$mimetype.$ext" in |
| 186 | + text/x-shellscript.*) lint_sh "${filename}" || lint_result=1 ;; |
| 187 | + *.go) lint_go "${filename}" || lint_result=1 ;; |
| 188 | + *.tf) lint_tf "${filename}" || lint_result=1 ;; |
| 189 | + *.md) lint_md "${filename}" || lint_result=1 ;; |
| 190 | + *.py) lint_py "${filename}" || lint_result=1 ;; |
200 | 191 | esac |
201 | 192 |
|
202 | | - spell_check "${filename}" || lint_result=1 |
| 193 | + # we don't want to spell check tar balls, binaries, Makefile and json files |
| 194 | + case "$mimetype.$ext" in |
| 195 | + *.tar | *.gz | *.json) ;; |
| 196 | + *.req | *.key | *.pem | *.crt) ;; |
| 197 | + application/x-executable.*) ;; |
| 198 | + text/x-makefile.*) ;; |
| 199 | + *) spell_check "${filename}" || lint_result=1 ;; |
| 200 | + esac |
203 | 201 |
|
204 | 202 | return $lint_result |
205 | 203 | } |
@@ -242,7 +240,7 @@ filter_out() { |
242 | 240 |
|
243 | 241 | list_files() { |
244 | 242 | if [ $# -gt 0 ]; then |
245 | | - find "$@" | grep -vE '(^|/)vendor/' |
| 243 | + find "$@" \( -name vendor -o -name .git \) -prune -o -type f |
246 | 244 | else |
247 | 245 | git ls-files --exclude-standard | grep -vE '(^|/)vendor/' |
248 | 246 | fi |
|
0 commit comments