Skip to content

chore: upgrade linter #1064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 110 additions & 122 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,137 +1,125 @@
linters-settings:
gosec:
excludes:
- G115 # Annoying and have a lot of false-positive results.
govet:
enable:
- shadow
gocyclo:
min-complexity: 15
dupl:
threshold: 120
goconst:
min-len: 2
min-occurrences: 3
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/ClickHouse/ch-go
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- hugeParam
- rangeValCopy
- exitAfterDefer
- whyNoLint
- singleCaseSwitch
- commentedOutCode
- appendAssign
- unnecessaryBlock
- redundantSprint
- octalLiteral
- ifElseChain
revive:
rules:
- name: unused-parameter
disabled: true

version: "2"
linters:
disable-all: true
default: none
enable:
- dogsled
- errcheck
- goconst
- gocritic
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- whitespace

# Do not enable:
# - wsl (too opinionated about newlines)
# - godox (todos are OK)
# - bodyclose (false positives on helper functions)
# - prealloc (not worth it in scope of this project)
# - maligned (same as prealloc)
# - funlen (gocyclo is enough)
# - gochecknoglobals (we know when it is ok to use globals)
# - depguard (broken)

issues:
exclude-use-default: false
exclude-rules:
# Document when API is stable
- text: "should have comment"
linters: [revive]

# Disable linters that are annoying in tests.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- funlen
- goconst
- gocognit
- scopelint
- lll

# Disable linters that are not needed for testing infra.
- path: internal/cht
linters: [gosec]

- path: _test\.go
text: "Combine"
linters: [gocritic]

# Check that equal to self is true
- linters: [gocritic]
source: "(assert|require).+Equal"
text: "dupArg"
path: _test\.go

# Ignore shadowing of err.
- linters: [govet]
text: 'declaration of "(err|ctx|log|lg|c)"'

# Probably some broken linter for generics?
- linters: [revive]
text: 'receiver-naming: receiver name \S+ should be consistent with previous receiver name \S+ for invalid-type'

# Ignore linters in main packages.
- path: main\.go
linters: [goconst, funlen, gocognit, gocyclo]

- path: main\.go
linters: [gosec]
text: "G307"

- source: 'func Fuzz.+\(f \*testing\.F\)'
linters: [stylecheck]
text: "ST1003" # underscores lol

- path: (internal|cmd)
linters: [revive]
text: "package-comments"

- linters: [revive]
text: "comment on exported const .+ should be of the form"
settings:
dupl:
threshold: 120
goconst:
min-len: 2
min-occurrences: 3
gocritic:
disabled-checks:
- hugeParam
- rangeValCopy
- exitAfterDefer
- whyNoLint
- singleCaseSwitch
- commentedOutCode
- appendAssign
- unnecessaryBlock
- redundantSprint
- octalLiteral
- ifElseChain
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
gosec:
excludes:
- G115
govet:
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
revive:
rules:
- name: unused-parameter
disabled: true
exclusions:
generated: strict
rules:
- linters:
- revive
text: should have comment
- linters:
- dupl
- errcheck
- funlen
- gocognit
- goconst
- gocyclo
- gosec
- lll
- scopelint
path: _test\.go
- linters:
- gosec
path: internal/cht
- linters:
- gocritic
path: _test\.go
text: Combine
- linters:
- gocritic
path: _test\.go
text: dupArg
source: (assert|require).+Equal
- linters:
- govet
text: declaration of "(err|ctx|log|lg|c)"
- linters:
- revive
text: 'receiver-naming: receiver name \S+ should be consistent with previous receiver name \S+ for invalid-type'
- linters:
- funlen
- gocognit
- goconst
- gocyclo
path: main\.go
- linters:
- gosec
path: main\.go
text: G307
- linters:
- staticcheck
text: ST1003
source: func Fuzz.+\(f \*testing\.F\)
- linters:
- revive
path: (internal|cmd)
text: package-comments
- linters:
- revive
text: comment on exported const .+ should be of the form
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/ClickHouse/ch-go
exclusions:
generated: strict
2 changes: 1 addition & 1 deletion internal/ztest/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (t *testLogSpy) Logf(format string, args ...interface{}) {
m := fmt.Sprintf(format, args...)
m = m[strings.IndexByte(m, '\t')+1:]
t.Messages = append(t.Messages, m)
t.TB.Log(m)
t.Log(m)
}

func (t *testLogSpy) AssertMessages(msgs ...string) {
Expand Down
2 changes: 1 addition & 1 deletion proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type staticAware struct {
}

func (s staticAware) Decode(r *Reader) error {
return s.AwareDecoder.DecodeAware(r, Version)
return s.DecodeAware(r, Version)
}

func aware(v AwareDecoder) Decoder {
Expand Down
Loading