Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
gwen917 committed Nov 27, 2023
1 parent 319fd8b commit ee93246
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Run Lint
run: |
./scripts/lint.sh
./scripts/lint.sh -l sol
golangci:
runs-on: ubuntu-20.04
Expand All @@ -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
61 changes: 52 additions & 9 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

0 comments on commit ee93246

Please sign in to comment.