File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed
Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 4646 files : ' \.go$'
4747 language : " script"
4848 description : " Runs `staticcheck`, install https://staticcheck.io/docs/"
49+ require_serial : true
4950
5051- id : golangci-lint
5152 name : " go golangci-lint"
Original file line number Diff line number Diff line change 1- #! /bin/sh
1+ #! /bin/bash
22
3- for DIR in $( echo " $@ " | xargs -n1 dirname| sort -u) ; do
4- staticcheck ./" $DIR "
3+ set -euo pipefail
4+
5+ cmd_options=()
6+ file_args=()
7+
8+ # we parse out cli options and file arguments
9+ # technically we allow for options to be passed after the file arguments, but
10+ # we know that pre-commit puts the file arguments last
11+ # also, we do not handle file names starting with a hyphen
12+ while [[ $# -gt 0 ]]; do
13+ if [[ " $1 " == -* ]]; then
14+ # If it's an option, ensure there's a value after it
15+ if [[ $# -ge 2 && -n " $2 " && " $2 " != -* ]]; then
16+ cmd_options+=(" $1 " " $2 " )
17+ shift 2
18+ else
19+ echo " Error: Missing value for key $1 "
20+ exit 1
21+ fi
22+ else
23+ file_args+=(" $1 " )
24+ shift
25+ fi
26+ done
27+
28+ if [[ ${# file_args[@]} -eq 0 ]]; then
29+ echo " Error: No file arguments provided"
30+ exit 1
31+ fi
32+
33+ packages=()
34+
35+ for DIR in $( echo " ${file_args[@]} " | xargs -n1 dirname | sort -u) ; do
36+ packages+=(" $DIR " )
37+ done
38+
39+ [[ ${# cmd_options[@]} -eq 0 ]] && cmd_options+=(" " )
40+
41+ for package in " ${packages[@]} " ; do
42+ staticcheck " ${cmd_options[@]} " ./" ${package} "
543done
You can’t perform that action at this time.
0 commit comments