migrate golangci-lint config to v2

upd conglangci-lint action
This commit is contained in:
onyx-and-iris 2026-02-15 10:43:35 +00:00
parent 7d41439ad6
commit 4f42aa7f36
2 changed files with 135 additions and 48 deletions

View File

@ -2,11 +2,11 @@ name: CI
on: on:
push: push:
branches: [ "main" ] branches: ['main']
paths: paths:
- '**.go' - '**.go'
pull_request: pull_request:
branches: [ "main" ] branches: ['main']
paths: paths:
- '**.go' - '**.go'
jobs: jobs:
@ -23,7 +23,8 @@ jobs:
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.24' go-version: '1.24'
- name: Install golangci-lint - name: golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest uses: golangci/golangci-lint-action@v9
- name: Run golangci-lint with:
run: golangci-lint run ./... version: v2.6.0
args: --config .golangci.yml

View File

@ -1,55 +1,141 @@
version: '2'
run: run:
# timeout for analysis, e.g. 30s, 3m, default is 1m
timeout: 3m timeout: 3m
# exclude test files
tests: true tests: true
go: '1.24'
linters: linters:
# Set to true runs only fast linters. disable: [dupl]
# Good option for 'lint on save', pre-commit hook or CI.
fast: true
disable-all: true
enable: enable:
- gosimple # Default enabled linters
- govet - errcheck # Check for unchecked errors
- ineffassign - govet # Go's built-in vetting tool
- staticcheck - ineffassign # Detect ineffectual assignments
- unused - staticcheck # Advanced static analysis
- gofmt - unused # Check for unused code
- gofumpt # Additional useful linters
- misspell - misspell # Detect common misspellings
- unparam - unparam # Check for unused function parameters
- gosec - gosec # Security checks
- asciicheck - asciicheck # Check for non-ASCII characters
- errname - errname # Check error variable names
- gci - godot # Check for missing periods in comments
- godot - revive # Highly configurable linter for style and correctness
- goimports - gocritic # Detect code issues and suggest improvements
- revive - 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: settings:
gofmt: misspell:
rewrite-rules: locale: UK
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
misspell: errcheck:
locale: UK check-type-assertions: true
check-blank: true
exclude-functions:
- fmt.Fprintf
- fmt.Fprintln
- fmt.Printf
- fmt.Println
- fmt.Errorf
errcheck: revive:
check-type-assertions: true 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 specific linters for test files
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- misspell
- golines
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/gobs-cli]
gci:
# Define import sections order
sections:
- standard # Standard library
- default # Everything else
- prefix(github.com/onyx-and-iris/gobs-cli) # Current module
gofumpt:
extra-rules: true # Enable additional formatting rules
exclusions:
warn-unused: true
paths:
- vendor
issues: issues:
max-same-issues: 0 max-same-issues: 0
max-issues-per-linter: 0 max-issues-per-linter: 0
exclude-use-default: false
exclude:
# gosec: Duplicated errcheck checks
- G104
exclude-files:
# Exclude vendor directory
- main_test.go