github.com/true-sqn/fabric@v2.1.1+incompatible/scripts/check_references.sh (about)

     1  #!/bin/bash
     2  
     3  #
     4  # Copyright IBM Corp All Rights Reserved.
     5  #
     6  # SPDX-License-Identifier: Apache-2.0
     7  #
     8  
     9  # Checks whether any files using go:generate directives make
    10  # references to their parent directories, instead of generating
    11  # the mock into the directory where it is being utilized
    12  echo "Checking for go:generate parent path references"
    13  OUTPUT="$(git ls-files "*.go" | grep -Ev 'vendor' | xargs grep 'go:generate.*\.\.')"
    14  if [[ -n "$OUTPUT" ]]; then
    15      echo "The following files contain references to parent directories in their go:generate directives."
    16      echo "Creating mocks in directories in which they are not used, can create errors that are not"
    17      echo "easily discoverable for code refactors that move the referenced code. It also implies that"
    18      echo "a mock for a remote interface is being defined in some place other that where it is being used"
    19      echo "It is best practice to generate the mock in the directory in which it will be used."
    20      echo "$OUTPUT"
    21      exit 1
    22  fi