Skip to content

Commit 49f56ff

Browse files
committed
golangci-lint: update lint config
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 26751c9 commit 49f56ff

File tree

1 file changed

+131
-136
lines changed

1 file changed

+131
-136
lines changed

.golangci.yml

Lines changed: 131 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,133 @@
22
# https://github.com/golangci/golangci-lint/blob/master/pkg/config/linters_settings.go
33
---
44
run:
5-
timeout: 1m
5+
timeout: 3m
66
issues-exit-code: 1
77
tests: true
8-
skip-dirs: []
9-
skip-dirs-use-default: true
10-
skip-files: []
8+
build-tags: []
119
allow-parallel-runners: true
10+
go: '1.22'
1211

1312
output:
14-
format: colored-line-number
13+
formats:
14+
- format: colored-line-number
15+
path: stdout
1516
print-issued-lines: true
1617
print-linter-name: true
17-
uniq-by-line: true
18+
uniq-by-line: false
1819
sort-results: true
1920

21+
linters:
22+
fast: true
23+
disable-all: true
24+
enable:
25+
- asasalint # check for pass []any as any in variadic func(...any)
26+
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
27+
- bidichk # Checks for dangerous unicode character sequences
28+
- bodyclose # checks whether HTTP response body is closed successfully
29+
- containedctx # containedctx is a linter that detects struct contained context.Context field
30+
- contextcheck # check whether the function uses a non-inherited context
31+
- cyclop # checks function and package cyclomatic complexity
32+
- decorder # check declaration order and count of types, constants, variables and functions
33+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
34+
- dupl # Tool for code clone detection
35+
- dupword # checks for duplicate words in the source code
36+
- durationcheck # check for two durations multiplied together
37+
- errcheck # errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases
38+
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
39+
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
40+
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
41+
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
42+
- exportloopref # checks for pointers to enclosing loop variables
43+
- funlen # Tool for detection of long functions
44+
- ginkgolinter # enforces standards of using ginkgo and gomega
45+
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid
46+
- gocognit # Computes and checks the cognitive complexity of functions
47+
- goconst # Finds repeated strings that could be replaced by a constant
48+
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
49+
- gocyclo # Computes and checks the cyclomatic complexity of functions
50+
- godot # Check if comments end in a period
51+
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
52+
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
53+
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
54+
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
55+
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
56+
- gosec # Inspects source code for security problems
57+
- gosimple # Linter for Go source code that specializes in simplifying code
58+
- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase
59+
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
60+
- grouper # An analyzer to analyze expression groups.
61+
- importas # Enforces consistent import aliases
62+
- inamedparam # reports interfaces with unnamed method parameters [fast: true, auto-fix: false]
63+
- ineffassign # Detects when assignments to existing variables are not used
64+
- interfacebloat # A linter that checks the number of methods inside an interface
65+
- intrange # intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
66+
- lll # Reports long lines
67+
- loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
68+
- maintidx # maintidx measures the maintainability index of each function.
69+
- makezero # Finds slice declarations with non-zero initial length
70+
- mirror # reports wrong mirror patterns of bytes/strings usage
71+
- misspell # Finds commonly misspelled English words in comments
72+
- musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false]
73+
- nakedret # Finds naked returns in functions greater than a specified function length
74+
- nestif # Reports deeply nested if statements
75+
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
76+
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
77+
- noctx # noctx finds sending http request without context.Context
78+
- nolintlint # Reports ill-formed or insufficient nolint directives
79+
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL.
80+
- prealloc # Finds slice declarations that could potentially be pre-allocated
81+
- predeclared # find code that shadows one of Go's predeclared identifiers
82+
- promlinter # Check Prometheus metrics naming via promlint
83+
- protogetter # Reports direct reads from proto message fields when getters should be used [fast: false, auto-fix: true]
84+
- reassign # Checks that package variables are not reassigned
85+
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
86+
- rowserrcheck # checks whether Err of rows is checked successfully
87+
- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false]
88+
- spancheck # Checks for mistakes with OpenTelemetry/Census spans. [fast: false, auto-fix: false]
89+
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
90+
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.
91+
- stylecheck # Stylecheck is a replacement for golint
92+
- tagalign # check that struct tags are well aligned
93+
- tagliatelle # Checks the struct tags.
94+
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
95+
- testableexamples # linter checks if examples are testable (have an expected output)
96+
- thelper # thelper detects Go test helpers without t.Helper() call and checks the consistency of test helpers
97+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
98+
- unconvert # Remove unnecessary type conversions
99+
- unparam # Reports unused function parameters
100+
- unused # Checks Go code for unused constants, variables, functions and types
101+
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library
102+
- varnamelen # checks that the length of a variable's name matches its scope
103+
- wastedassign # wastedassign finds wasted assignment statements.
104+
- whitespace # Tool for detection of leading and trailing whitespace
105+
- wrapcheck # Checks that errors returned from external packages are wrapped
106+
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false]
107+
20108
linters-settings:
21-
depguard:
22-
list-type: blacklist
23-
include-go-root: false
109+
asasalint:
110+
exclude: []
111+
use-builtin-exclusions: true
112+
ignore-test: false
113+
cyclop:
114+
max-complexity: 15
115+
# package-average:
116+
skip-tests: true
24117
dupl:
25118
threshold: 150
26119
errcheck:
27-
check-type-assertions: true
120+
disable-default-exclusions: false
121+
check-type-assertions: false
28122
check-blank: true
123+
ignore: ""
29124
# exclude: .errcheckignore
125+
exclude-functions: []
30126
errorlint:
31127
errorf: true
32128
asserts: true
33129
comparison: true
34130
funlen:
35-
lines: 100
131+
lines: 120
36132
statements: 60
37133
gocognit:
38134
min-complexity: 30
@@ -48,7 +144,6 @@ linters-settings:
48144
- style
49145
disabled-checks:
50146
- commentedOutCode
51-
- redundantSprint
52147
- whyNoLint
53148
settings:
54149
hugeParam:
@@ -66,35 +161,22 @@ linters-settings:
66161
simplify: true
67162
gofumpt:
68163
extra-rules: true
69-
goheader:
70-
values:
71-
const:
72-
AUTHOR: Go Language Server
73-
regexp:
74-
YEAR: '20\d\d'
75-
template: |-
76-
SPDX-FileCopyrightText: {{ YEAR }} The {{ AUTHOR }} Authors
77-
SPDX-License-Identifier: BSD-3-Clause
78164
goimports:
79-
local-prefixes: go.lsp.dev/protocol
80-
gosimple:
81-
go: 1.16
165+
local-prefixes: go.lsp.dev/protocol/
82166
govet:
83167
enable-all: true
84-
check-shadowing: true
85168
disable:
86169
- fieldalignment
87170
importas:
88171
alias: []
89172
no-unaliased: true
90173
lll:
91-
line-length: 120
174+
line-length: 200
92175
tab-width: 1
176+
maintidx:
177+
under: 15
93178
misspell:
94179
locale: US
95-
ignore-words:
96-
- cancelled
97-
- cancelling
98180
nakedret:
99181
max-func-lines: 30
100182
nestif:
@@ -103,140 +185,53 @@ linters-settings:
103185
simple: true
104186
range-loops: true
105187
for-loops: true
106-
staticcheck:
107-
go: 1.16
108188
testpackage:
109189
skip-regexp: '.*(export)_test\.go'
110190
unparam:
111191
check-exported: true
112-
algo: cha
113-
unused:
114-
go: 1.16
192+
varnamelen:
193+
max-distance: 5
194+
min-name-length: 1
195+
check-receiver: true
196+
check-return: true
197+
ignore-type-assert-ok: false
198+
ignore-map-index-ok: false
199+
ignore-chan-recv-ok: false
115200
whitespace:
116201
multi-if: true
117202
multi-func: true
118203

119-
linters:
120-
fast: false
121-
disabled:
122-
- exhaustivestruct # Checks if all struct's fields are initialized
123-
- forbidigo # Forbids identifiers
124-
- forcetypeassert # finds forced type assertions
125-
- gci # Gci control golang package import order and make it always deterministic.
126-
- gochecknoglobals # check that no global variables exist
127-
- gochecknoinits # Checks that no init functions are present in Go code
128-
- goconst # Finds repeated strings that could be replaced by a constant
129-
- godox # Tool for detection of FIXME, TODO and other comment keywords
130-
- goerr113 # Golang linter to check the errors handling expressions
131-
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
132-
- gomnd # An analyzer to detect magic numbers.
133-
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
134-
- gomodguard # Allow and block list linter for direct Go module dependencies.
135-
- interfacer # Linter that suggests narrower interface types
136-
- lll # Reports long lines
137-
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
138-
- promlinter # Check Prometheus metrics naming via promlint
139-
- scopelint # Scopelint checks for unpinned variables in go programs
140-
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
141-
- testpackage # TODO(zchee): enable: # linter that makes you use a separate _test package
142-
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
143-
- wrapcheck # TODO(zchee): enable: # Checks that errors returned from external packages are wrapped
144-
- wsl # Whitespace Linter
145-
enable:
146-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
147-
- bodyclose # checks whether HTTP response body is closed successfully
148-
- cyclop # checks function and package cyclomatic complexity
149-
- deadcode # Finds unused code
150-
- depguard # Go linter that checks if package imports are in a list of acceptable packages
151-
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
152-
- dupl # Tool for code clone detection
153-
- durationcheck # check for two durations multiplied together
154-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
155-
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
156-
- exhaustive # check exhaustiveness of enum switch statements
157-
- exportloopref # checks for pointers to enclosing loop variables
158-
- funlen # Tool for detection of long functions
159-
- gocognit # Computes and checks the cognitive complexity of functions
160-
- gocritic # Provides many diagnostics that check for bugs, performance and style issues.
161-
- gocyclo # Computes and checks the cyclomatic complexity of functions
162-
- godot # Check if comments end in a period
163-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
164-
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
165-
- goheader # Checks is file header matches to pattern
166-
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
167-
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
168-
- gosec # Inspects source code for security problems
169-
- gosimple # Linter for Go source code that specializes in simplifying a code
170-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
171-
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
172-
- importas # Enforces consistent import aliases
173-
- ineffassign # Detects when assignments to existing variables are not used
174-
- makezero # Finds slice declarations with non-zero initial length
175-
- misspell # Finds commonly misspelled English words in comments
176-
- nakedret # Finds naked returns in functions greater than a specified function length
177-
- nestif # Reports deeply nested if statements
178-
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
179-
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
180-
- noctx # noctx finds sending http request without context.Context
181-
- nolintlint # Reports ill-formed or insufficient nolint directives
182-
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
183-
- prealloc # Finds slice declarations that could potentially be preallocated
184-
- predeclared # find code that shadows one of Go's predeclared identifiers
185-
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
186-
- rowserrcheck # checks whether Err of rows is checked successfully
187-
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
188-
- structcheck # Finds unused struct fields
189-
- stylecheck # Stylecheck is a replacement for golint
190-
- tagliatelle # Checks the struct tags.
191-
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
192-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
193-
- unconvert # Remove unnecessary type conversions
194-
- unparam # Reports unused function parameters
195-
- unused # Checks Go code for unused constants, variables, functions and types
196-
- varcheck # Finds unused global variables and constants
197-
- wastedassign # wastedassign finds wasted assignment statements.
198-
- whitespace # Tool for detection of leading and trailing whitespace
199-
200204
issues:
205+
include:
206+
# include revive rules
207+
- "EXC0012"
208+
- "EXC0013"
209+
- "EXC0014"
210+
- "EXC0015"
201211
max-issues-per-linter: 0
212+
exclude-dirs-use-default: true
213+
exclude-dirs: []
214+
exclude-files: []
202215
max-same-issues: 0
203216
exclude-use-default: true
204217
exclude-rules:
205218
- path: _test\.go
206219
linters:
207-
- cyclop
208-
- dupl
209220
- errcheck
210221
- funlen
211222
- gocognit
212223
- goconst
213-
- gocritic
214224
- gocyclo
215225
- gosec
216-
- thelper
226+
- lll
217227
- wrapcheck
218228
- path: "(.*)?_example_test.go"
219229
linters:
220230
- gocritic
221231
# Exclude shadow checking on the variable named err
222-
- text: "shadow: declaration of \"(err|ok)\""
232+
- text: "shadow: declaration of \"err|ok|ctx\""
223233
linters:
224234
- govet
225-
# false positive
226-
- path: language.go
227-
text: "deprecatedComment: the proper format is `Deprecated: <text>`"
228-
# async
229-
- path: handler.go
230-
text: "Error return value of `conn.Notify` is not checked"
231-
linters:
232-
- errcheck
233-
- path: log.go
234-
text: "Error return value of `s.log.Write` is not checked"
235-
linters:
236-
- errcheck
237-
- path: deprecated.go
238-
linters:
239-
- lll
240-
- path: "(client|server)_json.go"
235+
- text: "continue with no blank line before"
241236
linters:
242237
- nlreturn

0 commit comments

Comments
 (0)