github.com/cosmos/cosmos-sdk@v0.50.10/scripts/go-lint-all.bash (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e -o pipefail
     4  
     5  REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
     6  export REPO_ROOT
     7  
     8  lint_module() {
     9    local root="$1"
    10    shift
    11    cd "$(dirname "$root")" &&
    12      echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" &&
    13      golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@"
    14  }
    15  export -f lint_module
    16  
    17  # if LINT_DIFF env is set, only lint the files in the current commit otherwise lint all files
    18  if [[ -z "${LINT_DIFF:-}" ]]; then
    19    find "${REPO_ROOT}" -type f -name go.mod -print0 |
    20      xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@"
    21  else
    22    if [[ -z $GIT_DIFF ]]; then
    23      GIT_DIFF=$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$) || true
    24    fi
    25  
    26    if [[ -z "$GIT_DIFF" ]]; then
    27      echo "no files to lint"
    28      exit 0
    29    fi
    30  
    31    for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do
    32      echo "linting $f [$(date -Iseconds -u)]" &&
    33      cd $f &&
    34      golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" &&
    35      cd $REPO_ROOT
    36    done
    37  fi