github.com/golang/dep@v0.5.4/hack/validate-gofmt.bash (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2017 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  #
     6  # This script will validate that `go fmt` has been ran
     7  # and is passing for certain directories in the project.
     8  #
     9  # Here we use `go list` to help determine which packages
    10  # we need to check for `go fmt`
    11  #
    12  # EXIT 0 - The check is successful
    13  # EXIT 1 - The check has failed
    14  
    15  PKGS=$(go list ./... | grep -v /vendor/)
    16  REPO_TLD="github.com/golang/dep"
    17  IGNORE_PKGS=". ./gps"
    18  
    19  for PKG in $PKGS; do
    20      RELATIVE_PATH="${PKG/$REPO_TLD/.}"
    21      i=0
    22      for IGNORE_PKG in $IGNORE_PKGS; do
    23          if [ "${IGNORE_PKG}" == $RELATIVE_PATH ]; then
    24              i=1
    25          fi
    26      done;
    27      if [ $i -eq 1 ]; then
    28          continue
    29      fi
    30  
    31      echo "Processing gofmt for: ${PKG}"
    32      gofmt -s -l $RELATIVE_PATH
    33      if [ $? -ne 0 ]; then
    34          echo "GO FMT FAILURE: ${PKG}"
    35          exit 1
    36      fi
    37  done;
    38  exit 0