github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/utils/repofmt/check_fmt.sh (about) 1 #!/bin/bash 2 3 set -eo pipefail 4 5 script_dir=$(dirname "$0") 6 cd $script_dir/../.. 7 8 go install golang.org/x/tools/cmd/goimports 9 10 paths=`find . -maxdepth 1 -mindepth 1 \( -name gen -prune -o -type d -print -o -type f -name '*.go' -print \)` 11 12 bad_files=$(goimports -l -local github.com/dolthub/dolt $paths) 13 if [ "$bad_files" != "" ]; then 14 echo "ERROR: The following files do not match goimports output:" 15 echo "$bad_files" 16 echo 17 echo "Please format the go code in the repository with './utils/repofmt/format_repo.sh'" 18 exit 1 19 fi 20 21 bad_files=$(find $paths -name '*.go' | while read f; do 22 if [[ $(awk '/import \(/{flag=1;next}/\)/{flag=0}flag' < $f | egrep -c '$^') -gt 2 ]]; then 23 echo $f 24 fi 25 done) 26 27 if [ "$bad_files" != "" ]; then 28 echo "ERROR: The following files have more than three import groups:" 29 echo "$bad_files" 30 echo 31 echo "Please format the go code in the repository with './utils/repofmt/format_repo.sh'" 32 exit 1 33 fi