From 0ed1c89aa08472bdfa045b13d1e3a97eb07bc4f8 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Fri, 29 Sep 2023 17:19:01 +0200 Subject: [PATCH] Use golangci-lint instead of golint (#400) --- .../assets/check-go-task/Taskfile.yml | 17 ++----- workflow-templates/assets/go/.golangci.yml | 7 +++ workflow-templates/check-go-task.md | 2 + workflow-templates/check-go-task.yml | 44 +++---------------- 4 files changed, 19 insertions(+), 51 deletions(-) create mode 100644 workflow-templates/assets/go/.golangci.yml diff --git a/workflow-templates/assets/check-go-task/Taskfile.yml b/workflow-templates/assets/check-go-task/Taskfile.yml index e72f2172..cd5488d6 100644 --- a/workflow-templates/assets/check-go-task/Taskfile.yml +++ b/workflow-templates/assets/check-go-task/Taskfile.yml @@ -22,18 +22,9 @@ tasks: dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" cmds: - | - if ! which golint &>/dev/null; then - echo "golint not installed or not in PATH. Please install: https://github.com/golang/lint#installation" + if ! which golangci-lint &>/dev/null; then + echo "golangci-lint not installed or not in PATH." + echo "Please install: https://golangci-lint.run/usage/install/#local-installation" exit 1 fi - - | - golint \ - {{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \ - {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} - - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml - go:vet: - desc: Check for errors in Go code - dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}" - cmds: - - go vet {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} + - golangci-lint run diff --git a/workflow-templates/assets/go/.golangci.yml b/workflow-templates/assets/go/.golangci.yml new file mode 100644 index 00000000..e51fc523 --- /dev/null +++ b/workflow-templates/assets/go/.golangci.yml @@ -0,0 +1,7 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/go/.golangci.yml +# See: https://golangci-lint.run/usage/configuration/ +issues: + exclude-use-default: false +linters: + enable: + - revive diff --git a/workflow-templates/check-go-task.md b/workflow-templates/check-go-task.md index 200fa294..d59847f8 100644 --- a/workflow-templates/check-go-task.md +++ b/workflow-templates/check-go-task.md @@ -12,6 +12,8 @@ Install the [`check-go-task.yml`](check-go-task.yml) GitHub Actions workflow to - [`Taskfile.yml`](assets/check-go-task/Taskfile.yml) - Linting and formatting [tasks](https://taskfile.dev/). - Install to: repository root (or merge into the existing `Taskfile.yml`). +- [`.golangci.yml`](assets/go/.golangci.yml) - Contains all the go-linting configurations. + - Install to: repository root as `.golangci.yml` - [`Taskfile.yml`](assets/go-task/Taskfile.yml) - `DEFAULT_GO_MODULE_PATH` and `DEFAULT_GO_PACKAGES` variables - Merge into `Taskfile.yml` diff --git a/workflow-templates/check-go-task.yml b/workflow-templates/check-go-task.yml index bfdfcdd4..bd9d127e 100644 --- a/workflow-templates/check-go-task.yml +++ b/workflow-templates/check-go-task.yml @@ -12,6 +12,7 @@ on: paths: - ".github/workflows/check-go-task.ya?ml" - "Taskfile.ya?ml" + - ".golangci.ya?ml" - "**/go.mod" - "**/go.sum" - "**.go" @@ -19,6 +20,7 @@ on: paths: - ".github/workflows/check-go-task.ya?ml" - "Taskfile.ya?ml" + - ".golangci.ya?ml" - "**/go.mod" - "**/go.sum" - "**.go" @@ -53,42 +55,6 @@ jobs: echo "result=$RESULT" >> $GITHUB_OUTPUT - check-errors: - name: check-errors (${{ matrix.module.path }}) - needs: run-determination - if: needs.run-determination.outputs.result == 'true' - runs-on: ubuntu-latest - permissions: - contents: read - - strategy: - fail-fast: false - - matrix: - module: - # TODO: add paths of all Go modules here - - path: ./ - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Install Task - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - version: 3.x - - - name: Check for errors - env: - GO_MODULE_PATH: ${{ matrix.module.path }} - run: task go:vet - check-outdated: name: check-outdated (${{ matrix.module.path }}) needs: run-determination @@ -159,8 +125,10 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} version: 3.x - - name: Install golint - run: go install golang.org/x/lint/golint@latest + - name: Install golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 - name: Check style env: