From 18f171675b823ed9e0e70810d8d6d06bb6597274 Mon Sep 17 00:00:00 2001 From: Paul Balogh Date: Sat, 20 Jan 2024 14:20:40 -0600 Subject: [PATCH] Add linting to CI Signed-off-by: Paul Balogh --- .github/workflows/ci.yml | 15 ------ .github/workflows/linter.yml | 42 ++++++++++++++++ .golangci.yml | 95 ++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/linter.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 652b65d..a92adf7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,21 +9,6 @@ on: pull_request: jobs: - check-modules: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install Go(lang) - uses: actions/setup-go@v5 - with: - go-version: 1.21.x - - name: Check module dependencies - run: | - go version - test -z "$(go mod tidy && git status go.* --porcelain)" - go mod verify - run-unit-tests: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..b7f4360 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,42 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + check-modules: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Go(lang) + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + - name: Check module dependencies + run: | + go version + test -z "$(go mod tidy && git status go.* --porcelain)" + go mod verify + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + - name: Retrieve golangci-lint version + run: | + echo "Version=$(head -n 1 "${GITHUB_WORKSPACE}/.golangci.yml" | tr -d '# ')" >> $GITHUB_OUTPUT + id: version + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: ${{ steps.version.outputs.Version }} + only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b51eb56 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,95 @@ +# v1.55.2 +# Please don't remove the first line. It is used in CI to determine the golangci-lint version. +run: + timeout: 5m + +issues: + exclude-rules: + - path: _(test|gen)\.go + linters: + - cyclop + - dupl + - gocognit + - funlen + - lll + - path: (cmd|env|migrations)\/ + linters: + - gochecknoglobals + +linters-settings: + govet: + check-shadowing: true + funlen: + lines: 80 + statements: 60 + forbidigo: + forbid: + - '^(fmt\\.Print(|f|ln)|print|println)$' + +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - contextcheck + - cyclop + - dogsled + - dupl + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exportloopref + - forbidigo + - forcetypeassert + - funlen + - gocheckcompilerdirectives + - gochecknoglobals + - gocognit + - goconst + - gocritic + - gofmt + - gofumpt + - goimports + - gomoddirectives + - goprintffuncname + - gosec + - gosimple + - govet + - importas + - ineffassign + - interfacebloat + - lll + - makezero + - misspell + - nakedret + - nestif + - nilerr + - nilnil + - noctx + - nolintlint + - nosprintfhostport + - paralleltest + - prealloc + - predeclared + - promlinter + - revive + - reassign + - rowserrcheck + - sqlclosecheck + - staticcheck + - stylecheck + - tenv + - tparallel + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + fast: false