github.com/yandex/pandora@v0.5.32/script/checkfmt.sh (about)

     1  #!/bin/bash
     2  
     3  
     4  test_fmt() {
     5      DIR="$1"
     6      hash goimports 2>&- || { echo >&2 "goimports not in PATH."; exit 1; }
     7  
     8      for file in $(find -L $DIR -type f -name "*.go" -not -path "./vendor/*" -not -path "./.idea/*")
     9      do
    10          output=`cat $file | goimports -l 2>&1`
    11          if test $? -ne 0
    12          then
    13              output=`echo "$output" | sed "s,<standard input>,$file,"`
    14              syntaxerrors="${list}${output}\n"
    15          elif test -n "$output"
    16          then
    17              list="${list}${file}\n"
    18          fi
    19      done
    20      exitcode=0
    21      if test -n "$syntaxerrors"
    22      then
    23          echo >&2 "goimports found syntax errors:"
    24          printf "$syntaxerrors"
    25          exitcode=1
    26      fi
    27      if test -n "$list"
    28      then
    29          echo >&2 "goimports needs to format these files (run make fmt and git add):"
    30          printf "$list"
    31          printf "\n"
    32          exitcode=1
    33      fi
    34      exit $exitcode
    35  }
    36  
    37  main() {
    38      test_fmt "$@"
    39  }
    40  
    41  main "$@"