Skip to content

Commit 09358ba

Browse files
committed
golangci-lint: update golangci-lint config
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
1 parent 4acd140 commit 09358ba

File tree

1 file changed

+135
-90
lines changed

1 file changed

+135
-90
lines changed

.golangci.yml

Lines changed: 135 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# https://golangci-lint.run/usage/configuration/
2+
# https://github.com/golangci/golangci-lint/blob/master/pkg/config/linters_settings.go
3+
---
14
run:
2-
timeout: 5m
5+
timeout: 1m
36
issues-exit-code: 1
47
tests: true
58
skip-dirs: []
69
skip-dirs-use-default: true
710
skip-files: []
8-
allow-parallel-runners: false
11+
allow-parallel-runners: true
912

1013
output:
1114
format: colored-line-number
@@ -15,19 +18,27 @@ output:
1518
sort-results: true
1619

1720
linters-settings:
21+
depguard:
22+
list-type: blacklist
23+
include-go-root: false
1824
dupl:
19-
threshold: 100
25+
threshold: 150
2026
errcheck:
2127
check-type-assertions: true
2228
check-blank: true
29+
# exclude: .errcheckignore
30+
errorlint:
31+
errorf: true
32+
asserts: true
33+
comparison: true
2334
funlen:
2435
lines: 100
2536
statements: 60
2637
gocognit:
27-
min-complexity: 20
38+
min-complexity: 30
2839
goconst:
2940
min-len: 3
30-
min-occurrences: 4
41+
min-occurrences: 3
3142
gocritic:
3243
enabled-tags:
3344
- diagnostic
@@ -46,146 +57,166 @@ linters-settings:
4657
rangeValCopy:
4758
sizeThreshold: 128
4859
gocyclo:
49-
min-complexity: 15
60+
min-complexity: 30
5061
godot:
5162
scope: declarations
5263
capital: false
5364
gofmt:
5465
simplify: true
66+
gofumpt:
67+
extra-rules: true
68+
goheader:
69+
values:
70+
const:
71+
AUTHOR: Go Language Server
72+
regexp:
73+
YEAR: '20\d\d'
74+
template: |-
75+
SPDX-FileCopyrightText: Copyright {{ YEAR }} The {{ AUTHOR }} Authors
76+
SPDX-License-Identifier: BSD-3-Clause
5577
goimports:
56-
local-prefixes: go.lsp.dev/protocol,go.lsp.dev
57-
golint:
58-
min-confidence: 0.3
78+
local-prefixes: go.lsp.dev/protocol
79+
gosimple:
80+
go: 1.16
5981
govet:
6082
enable-all: true
6183
check-shadowing: true
6284
disable:
63-
- fieldalignment # TODO(zchee)
64-
depguard:
65-
list-type: blacklist
66-
include-go-root: true
67-
# packages-with-error-message:
68-
# - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
85+
- fieldalignment
86+
importas:
87+
alias: []
88+
no-unaliased: true
6989
lll:
7090
line-length: 120
7191
tab-width: 1
72-
maligned:
73-
suggest-new: true
7492
misspell:
7593
locale: US
7694
ignore-words:
7795
- cancelled
7896
- cancelling
7997
nakedret:
8098
max-func-lines: 30
99+
nestif:
100+
min-complexity: 4
81101
prealloc:
82102
simple: true
83103
range-loops: true
84104
for-loops: true
105+
staticcheck:
106+
go: 1.16
85107
testpackage:
86108
skip-regexp: '.*(export)_test\.go'
87109
unparam:
88110
check-exported: true
89111
algo: cha
90112
unused:
91-
check-exported: false
113+
go: 1.16
92114
whitespace:
93115
multi-if: true
94116
multi-func: true
95117

96118
linters:
97119
fast: false
98120
disabled:
99-
- exhaustivestruct # Checks if all struct's fields are initialized
100-
- forbidigo # Forbids identifiers
101-
- gci # Gci control golang package import order and make it always deterministic
102-
- gochecknoglobals # check that no global variables exist
103-
- gochecknoinits # Checks that no init functions are present in Go code
104-
- gocyclo # Computes and checks the cyclomatic complexity of functions
105-
- godox # Tool for detection of FIXME, TODO and other comment keywords
106-
- goerr113 # Golang linter to check the errors handling expressions
107-
- gofumpt # Gofumpt checks whether code was gofumpt-ed
108-
- goheader # Checks is file header matches to pattern
109-
- gomnd # An analyzer to detect magic numbers
110-
- gomodguard # Allow and block list linter for direct Go module dependencies
111-
- gosec # Inspects source code for security problems
112-
- lll # Reports long lines
113-
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
114-
- paralleltest # TODO(zchee): paralleltest detects missing usage of t.Parallel() method in your Go test
115-
- scopelint # Scopelint checks for unpinned variables in go programs
116-
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed
117-
- testpackage # TODO(zchee): linter that makes you use a separate _test package
118-
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
119-
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
120-
- wrapcheck # TODO(zchee): enable: Checks that errors returned from external packages are wrapped
121-
- wsl # Whitespace Linter
121+
- exhaustivestruct # Checks if all struct's fields are initialized
122+
- forbidigo # Forbids identifiers
123+
- forcetypeassert # finds forced type assertions
124+
- gci # Gci control golang package import order and make it always deterministic.
125+
- gochecknoglobals # check that no global variables exist
126+
- gochecknoinits # Checks that no init functions are present in Go code
127+
- goconst # Finds repeated strings that could be replaced by a constant
128+
- godox # Tool for detection of FIXME, TODO and other comment keywords
129+
- goerr113 # Golang linter to check the errors handling expressions
130+
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
131+
- gomnd # An analyzer to detect magic numbers.
132+
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
133+
- gomodguard # Allow and block list linter for direct Go module dependencies.
134+
- interfacer # Linter that suggests narrower interface types
135+
- lll # Reports long lines
136+
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
137+
- promlinter # Check Prometheus metrics naming via promlint
138+
- scopelint # Scopelint checks for unpinned variables in go programs
139+
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
140+
- testpackage # TODO(zchee): enable: # linter that makes you use a separate _test package
141+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
142+
- wrapcheck # TODO(zchee): enable: # Checks that errors returned from external packages are wrapped
143+
- wsl # Whitespace Linter
122144
enable:
123-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
124-
- bodyclose # checks whether HTTP response body is closed successfully
125-
- deadcode # Finds unused code
126-
- depguard # Go linter that checks if package imports are in a list of acceptable packages
127-
- dogsled # Checks assignments with too many blank identifiers
128-
- dupl # Tool for code clone detection
129-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs
130-
- errorlint # source code linter for Go software that can be used to find code that will cause problemswith the error wrapping scheme introduced in Go 1.13
131-
- exhaustive # check exhaustiveness of enum switch statements
132-
- exportloopref # checks for pointers to enclosing loop variables
133-
- funlen # Tool for detection of long functions
134-
- gocognit # Computes and checks the cognitive complexity of functions
135-
- goconst # Finds repeated strings that could be replaced by a constant
136-
- gocritic # The most opinionated Go source code linter
137-
- godot # Check if comments end in a period
138-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
139-
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
140-
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
141-
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
142-
- gosimple # Linter for Go source code that specializes in simplifying a code
143-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
144-
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
145-
- ineffassign # Detects when assignments to existing variables are not used
146-
- makezero # Finds slice declarations with non-zero initial length
147-
- misspell # Finds commonly misspelled English words in comments
148-
- nakedret # Finds naked returns in functions greater than a specified function length
149-
- nestif # Reports deeply nested if statements
150-
- noctx # noctx finds sending http request without context.Context
151-
- nolintlint # Reports ill-formed or insufficient nolint directives
152-
- prealloc # Finds slice declarations that could potentially be preallocated
153-
- predeclared # find code that shadows one of Go's predeclared identifiers
154-
- rowserrcheck # checks whether Err of rows is checked successfully
155-
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
156-
- structcheck # Finds unused struct fields
157-
- stylecheck # Stylecheck is a replacement for golint
158-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
159-
- unconvert # Remove unnecessary type conversions
160-
- unparam # Reports unused function parameters
161-
- unused # Checks Go code for unused constants, variables, functions and types
162-
- varcheck # Finds unused global variables and constants
163-
- whitespace # Tool for detection of leading and trailing whitespace
145+
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
146+
- bodyclose # checks whether HTTP response body is closed successfully
147+
- cyclop # checks function and package cyclomatic complexity
148+
- deadcode # Finds unused code
149+
- depguard # Go linter that checks if package imports are in a list of acceptable packages
150+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
151+
- dupl # Tool for code clone detection
152+
- durationcheck # check for two durations multiplied together
153+
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
154+
- 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.
155+
- exhaustive # check exhaustiveness of enum switch statements
156+
- exportloopref # checks for pointers to enclosing loop variables
157+
- funlen # Tool for detection of long functions
158+
- gocognit # Computes and checks the cognitive complexity of functions
159+
- gocritic # Provides many diagnostics that check for bugs, performance and style issues.
160+
- gocyclo # Computes and checks the cyclomatic complexity of functions
161+
- godot # Check if comments end in a period
162+
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
163+
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
164+
- goheader # Checks is file header matches to pattern
165+
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
166+
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
167+
- gosec # Inspects source code for security problems
168+
- gosimple # Linter for Go source code that specializes in simplifying a code
169+
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
170+
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
171+
- importas # Enforces consistent import aliases
172+
- ineffassign # Detects when assignments to existing variables are not used
173+
- makezero # Finds slice declarations with non-zero initial length
174+
- misspell # Finds commonly misspelled English words in comments
175+
- nakedret # Finds naked returns in functions greater than a specified function length
176+
- nestif # Reports deeply nested if statements
177+
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
178+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
179+
- noctx # noctx finds sending http request without context.Context
180+
- nolintlint # Reports ill-formed or insufficient nolint directives
181+
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
182+
- prealloc # Finds slice declarations that could potentially be preallocated
183+
- predeclared # find code that shadows one of Go's predeclared identifiers
184+
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
185+
- rowserrcheck # checks whether Err of rows is checked successfully
186+
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
187+
- structcheck # Finds unused struct fields
188+
- stylecheck # Stylecheck is a replacement for golint
189+
- tagliatelle # Checks the struct tags.
190+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
191+
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
192+
- unconvert # Remove unnecessary type conversions
193+
- unparam # Reports unused function parameters
194+
- unused # Checks Go code for unused constants, variables, functions and types
195+
- varcheck # Finds unused global variables and constants
196+
- wastedassign # wastedassign finds wasted assignment statements.
197+
- whitespace # Tool for detection of leading and trailing whitespace
164198

165199
issues:
200+
max-issues-per-linter: 0
166201
max-same-issues: 0
167202
exclude-use-default: true
168203
exclude-rules:
169204
- path: _test\.go
170205
linters:
206+
- cyclop
171207
- dupl
172208
- errcheck
173209
- funlen
174210
- gocognit
175211
- goconst
176-
- gocyclo
177212
- gocritic
178-
- lll
179-
- maligned
213+
- gocyclo
214+
- gosec
215+
- thelper
180216
- wrapcheck
181217
- path: "(.*)?_example_test.go"
182218
linters:
183219
- gocritic
184-
# `TestMain` function is no longer required to call `os.Exit` since Go 1.15.
185-
# ref: https://golang.org/doc/go1.15#testing
186-
- text: "SA3000:"
187-
linters:
188-
- staticcheck
189220
# Exclude shadow checking on the variable named err
190221
- text: "shadow: declaration of \"(err|ok)\""
191222
linters:
@@ -202,3 +233,17 @@ issues:
202233
text: "Error return value of `s.log.Write` is not checked"
203234
linters:
204235
- errcheck
236+
- path: deprecated.go
237+
linters:
238+
- lll
239+
- path: "(client|server)_json.go"
240+
linters:
241+
- nlreturn
242+
- path: _gojay\.go
243+
linters:
244+
- cyclop
245+
- gocyclo
246+
- nlreturn
247+
- path: keys_gojay.go
248+
linters:
249+
- gosec

0 commit comments

Comments
 (0)