From ee932465814881d78c5f0cca035cfcb084a611bc Mon Sep 17 00:00:00 2001 From: Gwen Date: Mon, 27 Nov 2023 12:06:44 -0500 Subject: [PATCH] fix linter --- .github/workflows/linter.yml | 12 +++---- scripts/lint.sh | 61 ++++++++++++++++++++++++++++++------ scripts/versions.sh | 3 ++ 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index f07109407..914ba6a47 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -22,7 +22,7 @@ jobs: - name: Run Lint run: | - ./scripts/lint.sh + ./scripts/lint.sh -l sol golangci: runs-on: ubuntu-20.04 @@ -43,10 +43,6 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.54 - # To reproduce the linter locally, make sure to run golangci-lint from teleporter/tests - working-directory: ./teleporter/tests - args: --timeout 10m + - name: Run Lint + run: | + ./scripts/lint.sh -l go diff --git a/scripts/lint.sh b/scripts/lint.sh index e18528777..dc9941c5b 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -4,14 +4,57 @@ set -e -TELEPORTER_PATH=$( - cd "$(dirname "${BASH_SOURCE[0]}")" - cd .. && pwd -) - -cd $TELEPORTER_PATH/contracts/src -# "solhint **/*.sol" runs differently than "solhint '**/*.sol'", where the latter checks sol files -# in subdirectories. The former only checks sol files in the current directory and directories one level down. -solhint '**/*.sol' --config ./.solhint.json --ignore-path ./.solhintignore --max-warnings 0 +source ./scripts/versions.sh + +LINTER= +HELP= +while [ $# -gt 0 ]; do + case "$1" in + -l | --linter) LINTER=$2 ;; + -h | --help) HELP=true ;; + esac + shift +done + +if [ "$HELP" = true ]; then + echo "Usage: ./scripts/lint.sh [OPTIONS]" + echo "Lint Teleporter Solidity contracts and E2E tests Golang code." + echo "" + echo "Options:" + echo " -l, --linter Specify which linter (sol/go) to run. If empty, runs both solidity and go linters." + echo " -h, --help Print this help message" + exit 0 +fi + +function sollinter() { + # lint solidity contracts + echo "Linting Teleporter Solidity contracts..." + cd $TELEPORTER_PATH/contracts/src + # "solhint **/*.sol" runs differently than "solhint '**/*.sol'", where the latter checks sol files + # in subdirectories. The former only checks sol files in the current directory and directories one level down. + solhint '**/*.sol' --config ./.solhint.json --ignore-path ./.solhintignore --max-warnings 0 +} + +function golanglinter() { + # lint e2e tests go code + go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} + + echo "Linting Teleporter E2E tests Golang code..." + cd $TELEPORTER_PATH/tests + golangci-lint run --config=$TELEPORTER_PATH/.golangci.yml ./... +} + +if [ -z "$LINTER" ]; then + sollinter + golanglinter +elif [ "$LINTER" = "sol" ]; then + sollinter +elif [ "$LINTER" = "go" ]; then + golanglinter +else + echo "Invalid linter option: $LINTER" + exit 1 +fi + exit 0 \ No newline at end of file diff --git a/scripts/versions.sh b/scripts/versions.sh index a5be5e19f..2ace51819 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -28,3 +28,6 @@ export GO_VERSION=${GO_VERSION:-$(getDepVersion go).$GO_PATCH_VERSION} # Don't export them as they're used in the context of other calls AVALANCHE_VERSION=${AVALANCHE_VERSION:-$(getDepVersion github.com/ava-labs/avalanchego)} GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} + +# Set golangci-lint version +GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.55'}