From 1da96e4f30cdcb5011ca4f4421e43783c146aad3 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 15 Feb 2026 15:19:26 +0000 Subject: [PATCH] migrate golangci config to version 2 update golangci workflow --- .github/workflows/golang-ci.yml | 9 +- .golangci.yml | 174 ++++++++++++++++++++++++-------- 2 files changed, 136 insertions(+), 47 deletions(-) diff --git a/.github/workflows/golang-ci.yml b/.github/workflows/golang-ci.yml index a6aa5e6..358429a 100644 --- a/.github/workflows/golang-ci.yml +++ b/.github/workflows/golang-ci.yml @@ -23,7 +23,8 @@ jobs: uses: actions/setup-go@v5 with: go-version: '1.24' - - name: Install golangci-lint - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - - name: Run golangci-lint - run: golangci-lint run ./... + - name: golangci-lint + uses: golangci/golangci-lint-action@v9 + with: + version: v2.6.0 + args: --config .golangci.yml diff --git a/.golangci.yml b/.golangci.yml index 55de51c..9d695d3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,54 +1,142 @@ +version: '2' + run: - # timeout for analysis, e.g. 30s, 3m, default is 1m timeout: 3m - # exclude test files tests: true + go: '1.24' linters: - # Set to true runs only fast linters. - # Good option for 'lint on save', pre-commit hook or CI. - fast: true - - disable-all: true - + disable: [] enable: - - gosimple - - govet - - ineffassign - - staticcheck - - unused - - gofmt - - gofumpt - - misspell - - unparam - - gosec - - asciicheck - - errname - - gci - - godot - - goimports - - revive + # Default enabled linters + - errcheck # Check for unchecked errors + - govet # Go's built-in vetting tool + - ineffassign # Detect ineffectual assignments + - staticcheck # Advanced static analysis + - unused # Check for unused code + # Additional useful linters + - misspell # Detect common misspellings + - unparam # Check for unused function parameters + - gosec # Security checks + - asciicheck # Check for non-ASCII characters + - errname # Check error variable names + - godot # Check for missing periods in comments + - revive # Highly configurable linter for style and correctness + - gocritic # Detect code issues and suggest improvements + - gocyclo # Check for cyclomatic complexity + - dupl # Check for code duplication + - predeclared # Check for shadowing of predeclared identifiers + - copyloopvar # Check for loop variable capture in goroutines + - errorlint # Check for common mistakes in error handling + - goconst # Check for repeated strings that could be constants + - gosmopolitan # Check for non-portable code -linters-settings: - gofmt: - rewrite-rules: - - pattern: 'interface{}' - replacement: 'any' - - pattern: 'a[b:len(a)]' - replacement: 'a[b:]' + settings: + misspell: + locale: UK - misspell: - locale: UK + errcheck: + check-type-assertions: true + check-blank: true + exclude-functions: + - fmt.Fprintf + - fmt.Fprintln + - fmt.Printf + - fmt.Println + - fmt.Errorf - errcheck: - check-type-assertions: true + revive: + severity: warning + rules: + # Code quality and style + - name: exported + arguments: + - 'checkPrivateReceivers' + - 'sayRepetitiveInsteadOfStutters' + - name: var-naming + - name: package-comments + - name: range-val-in-closure + - name: time-naming + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: empty-block + - name: error-return + - name: error-strings + - name: error-naming + - name: if-return + - name: increment-decrement + - name: indent-error-flow + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + - name: unexported-return + - name: unreachable-code + - name: unused-parameter + - name: var-declaration + - name: blank-imports + - name: range + + # Disabled rules (can be enabled if needed) + # - name: line-length-limit + # arguments: [120] + # - name: function-length + # arguments: [50, 0] + # - name: cyclomatic + # arguments: [10] + + gosec: + excludes: + - G104 # Duplicated errcheck checks + - G115 # integer overflow conversion int -> uint32 + + exclusions: + warn-unused: false + rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + + paths: + - vendor + +# Formatters configuration +formatters: + # Enable specific formatters + enable: + - gofumpt # Stricter gofmt alternative + - goimports # Organizes imports + - gci # Controls import order/grouping + - golines # Enforces line length + + # Formatter-specific settings + settings: + goimports: + local-prefixes: [github.com/onyx-and-iris/ignr] + + gci: + # Define import sections order + sections: + - standard # Standard library + - default # Everything else + - prefix(github.com/onyx-and-iris/ignr) # Current module + + gofumpt: + extra-rules: true # Enable additional formatting rules + + exclusions: + warn-unused: true + + paths: + - vendor issues: - max-same-issues: 0 - max-issues-per-linter: 0 - exclude-use-default: false - exclude: - # gosec: Duplicated errcheck checks - - G104 - # gosec: integer overflow conversion int -> uint32 - - G115 + # Limit the number of same issues reported to avoid spam + max-same-issues: 50 + + # Limit the number of issues per linter to keep output manageable + max-issues-per-linter: 100