From 6fb902949376b19de498730b45365db193aef173 Mon Sep 17 00:00:00 2001 From: sesheffield Date: Wed, 31 Jul 2024 16:23:44 -0400 Subject: [PATCH] chore(linter): update Golang linter configuration (#1977) * update golinter + add go sec * add golangci.yml Co-authored-by: @faddat jacobgadikian@gmail.com * update * update * fix release version * remove sec, update from pr comments, cleanup golangci.yml to not break on master * remove @faddat, not valid codeowner * remove unnecessary make command * remove incorrectly named golangci.yml file * add --new-from-rev * use master instead of main * remove extra echo * set the exports properly * add setup go to work with act * add some docs to golangci linter * test new-from-rev * enable more linters, but app.go back * verify issues-exit-code being gone * put it back * enable more linters * remove exclusions --- .github/CODEOWNERS | 3 + .github/workflows/ci-lint.yml | 24 +++++-- .golangci-version | 1 + .golangci.yml | 120 ++++++++++++++++++++++++++++++++++ golangci.yml | 52 --------------- 5 files changed, 143 insertions(+), 57 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .golangci-version create mode 100644 .golangci.yml delete mode 100644 golangci.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..716e9a45e9 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners +# Global rule: +* @rhuairahrighairidh @karzak @pirtleshell @drklee3 @nddeluca @DracoLi @evgeniy-scherbina @sesheffield \ No newline at end of file diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index 7c36c83587..6580586c80 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -7,11 +7,25 @@ jobs: uses: ./.github/workflows/proto.yml golangci-lint: runs-on: ubuntu-latest + permissions: + checks: write # allow write access to checks to allow the action to annotate code in the PR. steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + with: { fetch-depth: 0 } + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: go.mod + - name: Load Version + id: load-version + run: | + GOLANGCI_VERSION=$(cat .golangci-version) + REV=$(git merge-base origin/master HEAD) + echo "GOLANGCI_VERSION=$GOLANGCI_VERSION" >> $GITHUB_ENV + echo "REV=$REV" >> $GITHUB_ENV - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 + uses: golangci/golangci-lint-action@v6 with: - github_token: ${{ secrets.github_token }} - reporter: github-pr-review - golangci_lint_flags: --timeout 10m + version: ${{ env.GOLANGCI_VERSION }} + args: -v -c .golangci.yml --new-from-rev ${{ env.REV }} diff --git a/.golangci-version b/.golangci-version new file mode 100644 index 0000000000..35345c2fe3 --- /dev/null +++ b/.golangci-version @@ -0,0 +1 @@ +v1.59 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..88c4d74415 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,120 @@ +run: + timeout: 20m # set maximum time allowed for the linter to run. If the linting process exceeds this duration, it will be terminated + modules-download-mode: readonly # Ensures that modules are not modified during the linting process + allow-parallel-runners: true # enables parallel execution of linters to speed up linting process + +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - containedctx + - contextcheck + - decorder + - dogsled +# - dupl +# - dupword + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint +# - exhaustive + - exportloopref + - funlen + - gci + - ginkgolinter + - gocheckcompilerdirectives +# - gochecknoglobals +# - gochecknoinits + - goconst + - gocritic + - godox + - gofmt +# - gofumpt + - goheader + - goimports + - mnd +# - gomodguard + - goprintffuncname +# - gosec + - gosimple + - govet + - grouper + - importas + - ineffassign +# - interfacebloat + - lll + - loggercheck + - makezero + - mirror + - misspell + - musttag +# - nakedret +# - nestif + - nilerr +# - nilnil +# - noctx + - nolintlint +# - nonamedreturns + - nosprintfhostport + - prealloc + - predeclared + - promlinter +# - reassign + - revive + - rowserrcheck + - staticcheck +# - stylecheck + - tagalign +# - testpackage +# - thelper +# - tparallel + - typecheck +# - unconvert + - unparam + - unused +# - usestdlibvars + - wastedassign +# - whitespace + - wrapcheck + + +linters-settings: + errcheck: + check-blank: true # check for assignments to the blank identifier '_' when errors are returned + check-type-assertions: false # check type assertion + errorlint: + check-generated: false # disabled linting of generated files + default-signifies-exhaustive: false # exhaustive handling of error types + exhaustive: + default-signifies-exhaustive: false # exhaustive handling of error types + gci: + sections: # defines the order of import sections + - standard + - default + goconst: + min-len: 3 # min length for string constants to be checked + min-occurrences: 3 # min occurrences of the same constant before it's flagged + godox: + keywords: # specific keywords to flag for further action + - BUG + - FIXME + - HACK + lll: + line-length: 120 + nolintlint: + allow-leading-space: false + require-explanation: true + require-specific: true + unparam: + check-exported: true # checks exported functions and methods for unused params + misspell: + locale: US + ignore-words: expect + prealloc: + simple: true # enables simple preallocation checks + range-loops: true # enabled preallocation checks in range loops + for-loops: false # disables preallocation checks in for loops diff --git a/golangci.yml b/golangci.yml deleted file mode 100644 index 371e83fa8c..0000000000 --- a/golangci.yml +++ /dev/null @@ -1,52 +0,0 @@ -run: - tests: false -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m - -linters: - disable-all: true - enable: - - bodyclose - - deadcode - - depguard - - dogsled - # - errcheck - - goconst - - gocritic - - gofmt - - goimports - - golint - - gosec - - gosimple - - govet - - ineffassign - - interfacer - - maligned - - misspell - - nakedret - - prealloc - - scopelint - - staticcheck - - structcheck - - stylecheck - - typecheck - - unconvert - - unused - - misspell - - wsl - -issues: - exclude-rules: - - text: "Use of weak random number generator" - linters: - - gosec - - text: "comment on exported var" - linters: - - golint - -linters-settings: - dogsled: - max-blank-identifiers: 3 - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true