Skip to content

Commit 4a7328c

Browse files
committed
define golangci-lint config
1 parent 0c0bed1 commit 4a7328c

File tree

8 files changed

+587
-150
lines changed

8 files changed

+587
-150
lines changed

config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,16 @@ func NewConfig(conf string) (Config, error) {
233233
}
234234

235235
// ============ validate and update the config ============
236-
if err := c.validateCustomLinters(); err != nil {
236+
if err = c.validateCustomLinters(); err != nil {
237237
return c, err
238238
}
239-
if err := c.parseCloneURLs(); err != nil {
239+
if err = c.parseCloneURLs(); err != nil {
240240
return c, err
241241
}
242-
if err := c.validateRefs(); err != nil {
242+
if err = c.validateRefs(); err != nil {
243243
return c, err
244244
}
245-
if err := c.parseIssueReferences(); err != nil {
245+
if err = c.parseIssueReferences(); err != nil {
246246
return c, err
247247
}
248248

config/linters-config/.golangci.goplus.yml

Lines changed: 119 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,126 @@
1-
# 这是我们当前内部使用的配置文件,会基于实际的变化和我们的认知而迭代,仅供参考
1+
# This is the recommended config for golangci-lint based on our experience and opinion.
2+
# And it will be continuously updated.
3+
#
4+
# Philosophy:
5+
# 1. Strict but practical: We aim to detect real issues that require fixing
6+
# 2. High quality: We enable carefully selected, industry-proven linters(linters with 100+ stars)
7+
# 3. Best practices: Leverage community-accepted Go best practices
8+
# 4. False positive minimization: Configured to reduce noise while maintaining effectiveness
9+
#
10+
# Feel free to customize the config to your own project.
11+
12+
run:
13+
# control the resource usage of golangci-lint to avoid OOM
14+
concurrency: 4
15+
# Default: 1m
16+
timeout: 3m
17+
18+
linters:
19+
disable-all: true
20+
enable:
21+
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
22+
- gosimple # specializes in simplifying a code
23+
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
24+
- ineffassign # detects when assignments to existing variables are not used
25+
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
26+
- unused # checks for unused constants, variables, functions and types
27+
- bidichk # security checks for dangerous unicode character sequences
28+
- bodyclose # checks whether HTTP response body is closed successfully
29+
- copyloopvar # detects places where loop variables are copied (Go 1.22+)
30+
- dupl # tool for code clone detection
31+
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
32+
- exhaustive # checks exhaustiveness of enum switch statements
33+
- gocognit # computes and checks the cognitive complexity of functions
34+
- goconst # finds repeated strings that could be replaced by a constant
35+
- gocritic # provides diagnostics that check for bugs, performance and style issues
36+
- gocyclo # computes and checks the cyclomatic complexity of functions
37+
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
38+
- gosec # inspects source code for security problems
39+
- nakedret # finds naked returns in functions greater than a specified function length
40+
- noctx # finds sending http request without context.Context
41+
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
42+
- sloglint # ensure consistent code style when using log/slog
43+
- stylecheck # is a replacement for golint
44+
- testifylint # checks usage of github.com/stretchr/testify
45+
- unconvert # removes unnecessary type conversions
46+
- unparam # reports unused function parameters
47+
- gci # enforce consistent imports
48+
- misspell # check for spelling mistakes
49+
- prealloc # checks for slice pre-allocation
50+
51+
issues:
52+
exclude-rules:
53+
- source: "(noinspection|TODO)"
54+
linters: [godot]
55+
- source: "//noinspection"
56+
linters: [gocritic]
57+
- path: "_test\\.go"
58+
linters:
59+
- bodyclose
60+
- dupl
61+
- revive # too strict for test scenarios
62+
- gocognit # no need to check on test files
63+
- errcheck
64+
- funlen
65+
- goconst
66+
- gosec
67+
- noctx
68+
- wrapcheck
269

370
linters-settings:
4-
paralleltest:
5-
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
71+
errcheck:
72+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
73+
# Such cases aren't reported by default.
74+
# Default: false
75+
check-type-assertions: true
76+
exclude-functions:
77+
- (net/http.ResponseWriter).Write
78+
- (net/http.ResponseWriter).WriteHeader
79+
- (net/http.ResponseWriter).Header
80+
- (*flag.FlagSet).Parse
81+
82+
exhaustive:
83+
# Presence of "default" case in switch statements satisfies exhaustiveness,
84+
# even if all enum members are not listed.
685
# Default: false
7-
# see: https://github.com/qiniu/reviewbot/issues/149
8-
ignore-missing: true
9-
# Ignore missing calls to `t.Parallel()` in subtests. Top-level tests are
10-
# still required to have `t.Parallel`, but subtests are allowed to skip it.
86+
default-signifies-exhaustive: true
87+
88+
gocritic:
89+
# too many false positives
90+
disabled-checks:
91+
- appendAssign
92+
93+
govet:
94+
# Enable all analyzers.
1195
# Default: false
12-
ignore-missing-subtests: true
96+
enable-all: true
97+
# Disable analyzers by name.
98+
# Run `go tool vet help` to see all analyzers.
99+
# Default: []
100+
disable:
101+
- fieldalignment # too strict
102+
103+
sloglint:
104+
# Enforce not using global loggers.
105+
# Values:
106+
# - "": disabled
107+
# - "all": report all global loggers
108+
# - "default": report only the default slog logger
109+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global
110+
# Default: ""
111+
no-global: "all"
112+
# Enforce using methods that accept a context.
113+
# Values:
114+
# - "": disabled
115+
# - "all": report all contextless calls
116+
# - "scope": report only if a context exists in the scope of the outermost function
117+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#context-only
118+
# Default: ""
119+
context: "scope"
120+
13121
revive:
14122
enable-all-rules: true
15123
rules:
16-
- name: unused-parameter
17-
disabled: true
18-
- name: unused-receiver
19-
disabled: true
20-
- name: blank-imports
21-
disabled: true
22-
- name: unexported-return
23-
disabled: true
24124
- name: line-length-limit
25125
disabled: true
26126
- name: cognitive-complexity
@@ -29,6 +129,8 @@ linters-settings:
29129
disabled: true
30130
- name: max-public-structs
31131
disabled: true
132+
- name: unused-parameter
133+
disabled: true
32134
- name: import-shadowing
33135
disabled: true
34136
- name: unused-receiver
@@ -39,66 +141,6 @@ linters-settings:
39141
disabled: true
40142
- name: cyclomatic
41143
arguments: [50]
42-
# revive 的 unhandled-error 误报太多, 本身已有 errcheck 检查
144+
# too many false positives
43145
- name: unhandled-error
44146
disabled: true
45-
46-
errcheck:
47-
exclude-functions:
48-
- (net/http.ResponseWriter).Write
49-
- (net/http.ResponseWriter).WriteHeader
50-
- (net/http.ResponseWriter).Header
51-
- (*flag.FlagSet).Parse
52-
53-
gocritic:
54-
disabled-checks:
55-
- appendAssign
56-
57-
exhaustive:
58-
default-signifies-exhaustive: true
59-
60-
issues:
61-
exclude-rules:
62-
- path: '(.+)_test\.go'
63-
linters:
64-
- funlen
65-
- goconst
66-
- noctx
67-
- revive
68-
- gocognit
69-
70-
linters:
71-
# Enable all available linters.
72-
enable-all: true
73-
# Disable specific linter
74-
disable:
75-
- nlreturn # see https://github.com/qiniu/reviewbot/issues/148
76-
- wrapcheck # see https://github.com/qiniu/reviewbot/issues/180
77-
- gochecknoglobals # see https://github.com/qiniu/reviewbot/issues/182
78-
- varnamelen # seems too arbitrary
79-
- testpackage # seems too arbitrary
80-
- depguard # seems too arbitrary
81-
- cyclop # seems too arbitrary
82-
- exhaustruct # seems too arbitrary
83-
- execinquery # deprecated
84-
- gomnd # deprecated
85-
- funlen # seems too arbitrary
86-
- lll # seems too arbitrary
87-
- mnd # seems too arbitrary
88-
- nilnil # seems too arbitrary
89-
- gofmt # there is a more elegant implementation. see ./internal/linters/go/gofmt/
90-
- wsl # seems too arbitrary
91-
- nonamedreturns # seems too arbitrary
92-
- ireturn # seems too arbitrary. also see: https://github.com/go-proverbs/go-proverbs.github.io/issues/37
93-
- godox # seems too arbitrary
94-
- gochecknoinits # see too many false positives
95-
- gofumpt # see too many false positives
96-
- tagliatelle # see too many false positives
97-
- intrange # see too many false positives
98-
- gosmopolitan # see too many false positives
99-
- canonicalheader # see https://github.com/qiniu/reviewbot/issues/457
100-
- gomoddirectives # superseded by gomodcheck
101-
- tagalign # see too many false positives
102-
- interfacebloat # seems too arbitrary
103-
- forbidigo # no requirement or necessity to prohibit the use of fmt
104-

0 commit comments

Comments
 (0)