diff --git a/.golangci.yml b/.golangci.yml index 14a41aa4..72e7a7c2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,158 +1,165 @@ +version: "2" linters: + default: none enable: - - gosimple - - typecheck - - govet - - errcheck - - staticcheck - - unused - - dupl - #- gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time. - - gofmt - - misspell - - gocritic - bidichk - - ineffassign - - revive - - gofumpt - depguard + - dupl + - errcheck + - gocritic + - govet + - ineffassign + - misspell - nakedret - - unconvert - - wastedassign - nolintlint - - stylecheck - enable-all: false - disable-all: true - fast: false - -run: - timeout: 10m - -linters-settings: - stylecheck: - checks: ["all", "-ST1005", "-ST1003"] - nakedret: - max-func-lines: 0 - gocritic: - disabled-checks: - - ifElseChain - - singleCaseSwitch # Every time this occurred in the code, there was no other way. - revive: - ignore-generated-header: false - severity: warning - confidence: 0.8 - errorCode: 1 - warningCode: 1 + - revive + - staticcheck + - unconvert + - unused + - wastedassign + settings: + depguard: + rules: + main: + deny: + - pkg: io/ioutil + desc: use os or io instead + gocritic: + disabled-checks: + - ifElseChain + - singleCaseSwitch + nakedret: + max-func-lines: 0 + revive: + confidence: 0.8 + severity: warning + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: duplicated-imports + - name: modifies-value-receiver + staticcheck: + checks: + - all + - -ST1003 + - -ST1005 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling rules: - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: error-return - - name: error-strings - - name: error-naming - - name: exported - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: package-comments - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: duplicated-imports - - name: modifies-value-receiver - gofumpt: - extra-rules: true - depguard: - rules: - main: - deny: - - pkg: io/ioutil - desc: use os or io instead - -issues: - exclude-rules: - # Exclude some linters from running on tests files. - - path: _test\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - unparam - - staticcheck - - path: models/migrations/v - linters: - - gocyclo - - errcheck - - dupl - - gosec - - linters: - - dupl - text: "webhook" - - linters: - - gocritic - text: "`ID' should not be capitalized" - - path: modules/templates/helper.go - linters: - - gocritic - - linters: - - unused - text: "swagger" - - path: contrib/pr/checkout.go - linters: - - errcheck - - path: models/issue.go - linters: - - errcheck - - path: models/migrations/ - linters: - - errcheck - - path: modules/log/ - linters: - - errcheck - - path: routers/api/v1/repo/issue_subscription.go - linters: - - dupl - - path: routers/repo/view.go - linters: - - dupl - - path: models/migrations/ - linters: - - unused - - linters: - - staticcheck - text: "argument x is overwritten before first use" - - path: modules/httplib/httplib.go - linters: - - staticcheck - # Enabling this would require refactoring the methods and how they are called. - - path: models/issue_comment_list.go - linters: - - dupl - - linters: - - misspell - text: '`Unknwon` is a misspelling of `Unknown`' - - path: models/update.go - linters: - - unused - - path: cmd/dump.go - linters: - - dupl - - text: "commentFormatting: put a space between `//` and comment text" - linters: - - gocritic - - text: "exitAfterDefer:" - linters: - - gocritic - - path: modules/graceful/manager_windows.go - linters: - - staticcheck - text: "svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead." - - path: models/user/openid.go - linters: - - golint + - linters: + - dupl + - errcheck + - gocyclo + - gosec + - staticcheck + - unparam + path: _test\.go + - linters: + - dupl + - errcheck + - gocyclo + - gosec + path: models/migrations/v + - linters: + - dupl + text: webhook + - linters: + - gocritic + text: '`ID'' should not be capitalized' + - linters: + - gocritic + path: modules/templates/helper.go + - linters: + - unused + text: swagger + - linters: + - errcheck + path: contrib/pr/checkout.go + - linters: + - errcheck + path: models/issue.go + - linters: + - errcheck + path: models/migrations/ + - linters: + - errcheck + path: modules/log/ + - linters: + - dupl + path: routers/api/v1/repo/issue_subscription.go + - linters: + - dupl + path: routers/repo/view.go + - linters: + - unused + path: models/migrations/ + - linters: + - staticcheck + text: argument x is overwritten before first use + - linters: + - staticcheck + path: modules/httplib/httplib.go + - linters: + - dupl + path: models/issue_comment_list.go + - linters: + - misspell + text: '`Unknwon` is a misspelling of `Unknown`' + - linters: + - unused + path: models/update.go + - linters: + - dupl + path: cmd/dump.go + - linters: + - gocritic + text: 'commentFormatting: put a space between `//` and comment text' + - linters: + - gocritic + text: 'exitAfterDefer:' + - linters: + - staticcheck + path: modules/graceful/manager_windows.go + text: 'svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead.' + - linters: + - golint + path: models/user/openid.go + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - gofumpt + settings: + gofumpt: + extra-rules: true + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 82df4a96..619f0cd5 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ GO_FMT_FILES := $(shell find . -type f -name "*.go" ! -name "generated.*") GOFILES := $(shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*") MOCKERY_PACKAGE ?= github.com/vektra/mockery/v2@v2.53.4 # renovate: datasource=go -GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8 # renovate: datasource=go +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.2.2 # renovate: datasource=go DOCKER_IMAGE ?= gitea/act_runner DOCKER_TAG ?= nightly