Skip to content

Commit 4b9fbf1

Browse files
- Conform golang versioning.
1 parent 112971a commit 4b9fbf1

File tree

3 files changed

+524
-323
lines changed

3 files changed

+524
-323
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313

1414
env:
15-
GOLANGCI_LINT_VERSION: ${{ vars.GOLANGCI_LINT_VERSION == '' && 'v1.59.1' || vars.GOLANGCI_LINT_VERSION }}
15+
GOLANGCI_LINT_VERSION: ${{ vars.GOLANGCI_LINT_VERSION == '' && 'v2.2.0' || vars.GOLANGCI_LINT_VERSION }}
1616
DEFAULT_STEP_TIMEOUT: ${{ vars.DEFAULT_STEP_TIMEOUT_MIN == '' && '20' || vars.DEFAULT_STEP_TIMEOUT_MIN }}
1717

1818
jobs:
@@ -25,7 +25,7 @@ jobs:
2525
- name: Setup Go environment
2626
uses: actions/[email protected]
2727
with:
28-
go-version: '1.22.0'
28+
go-version: '1.23.0'
2929
cache: false
3030

3131
- name: Check workflow files

.golangci.bck.yml

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
# This code is licensed under the terms of the MIT license.
2+
3+
## StackQL Acknowledgment: This file is sourced from https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322.
4+
## StackQL Acknowledgment: We profusely thank the creator.
5+
6+
## Golden config for golangci-lint v1.51.2
7+
#
8+
# This is the best config for golangci-lint based on my experience and opinion.
9+
# It is very strict, but not extremely strict.
10+
# Feel free to adopt and change it for your needs.
11+
12+
# version: "2"
13+
14+
run:
15+
# Timeout for analysis, e.g. 30s, 5m.
16+
# Default: 1m
17+
timeout: 10m
18+
19+
20+
# This file contains only configs which differ from defaults.
21+
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
22+
linters-settings:
23+
cyclop:
24+
# The maximal code complexity to report.
25+
# Default: 10
26+
max-complexity: 30
27+
# The maximal average package complexity.
28+
# If it's higher than 0.0 (float) the check is enabled
29+
# Default: 0.0
30+
package-average: 10.0
31+
32+
errcheck:
33+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
34+
# Such cases aren't reported by default.
35+
# Default: false
36+
check-type-assertions: true
37+
38+
exhaustive:
39+
# Program elements to check for exhaustiveness.
40+
# Default: [ switch ]
41+
check:
42+
- switch
43+
- map
44+
45+
exhaustruct:
46+
# List of regular expressions to exclude struct packages and names from check.
47+
# Default: []
48+
exclude:
49+
# std libs
50+
- "^net/http.Client$"
51+
- "^net/http.Cookie$"
52+
- "^net/http.Request$"
53+
- "^net/http.Response$"
54+
- "^net/http.Server$"
55+
- "^net/http.Transport$"
56+
- "^net/url.URL$"
57+
- "^os/exec.Cmd$"
58+
- "^reflect.StructField$"
59+
# public libs
60+
- "^github.com/Shopify/sarama.Config$"
61+
- "^github.com/Shopify/sarama.ProducerMessage$"
62+
- "^github.com/mitchellh/mapstructure.DecoderConfig$"
63+
- "^github.com/prometheus/client_golang/.+Opts$"
64+
- "^github.com/spf13/cobra.Command$"
65+
- "^github.com/spf13/cobra.CompletionOptions$"
66+
- "^github.com/stretchr/testify/mock.Mock$"
67+
- "^github.com/testcontainers/testcontainers-go.+Request$"
68+
- "^github.com/testcontainers/testcontainers-go.FromDockerfile$"
69+
- "^golang.org/x/tools/go/analysis.Analyzer$"
70+
- "^google.golang.org/protobuf/.+Options$"
71+
- "^gopkg.in/yaml.v3.Node$"
72+
73+
funlen:
74+
# Checks the number of lines in a function.
75+
# If lower than 0, disable the check.
76+
# Default: 60
77+
lines: 100
78+
# Checks the number of statements in a function.
79+
# If lower than 0, disable the check.
80+
# Default: 40
81+
statements: 50
82+
83+
gocognit:
84+
# Minimal code complexity to report.
85+
# Default: 30 (but we recommend 10-20)
86+
min-complexity: 20
87+
88+
gocritic:
89+
# Settings passed to gocritic.
90+
# The settings key is the name of a supported gocritic checker.
91+
# The list of supported checkers can be find in https://go-critic.github.io/overview.
92+
settings:
93+
captLocal:
94+
# Whether to restrict checker to params only.
95+
# Default: true
96+
paramsOnly: false
97+
underef:
98+
# Whether to skip (*x).method() calls where x is a pointer receiver.
99+
# Default: true
100+
skipRecvDeref: false
101+
102+
mnd:
103+
# List of function patterns to exclude from analysis.
104+
# Values always ignored: `time.Date`,
105+
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
106+
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
107+
# Default: []
108+
ignored-functions:
109+
- os.Chmod
110+
- os.Mkdir
111+
- os.MkdirAll
112+
- os.OpenFile
113+
- os.WriteFile
114+
- prometheus.ExponentialBuckets
115+
- prometheus.ExponentialBucketsRange
116+
- prometheus.LinearBuckets
117+
118+
gomodguard:
119+
blocked:
120+
# List of blocked modules.
121+
# Default: []
122+
modules:
123+
- github.com/golang/protobuf:
124+
recommendations:
125+
- google.golang.org/protobuf
126+
reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules"
127+
- github.com/satori/go.uuid:
128+
recommendations:
129+
- github.com/google/uuid
130+
reason: "satori's package is not maintained"
131+
- github.com/gofrs/uuid:
132+
recommendations:
133+
- github.com/google/uuid
134+
reason: "gofrs' package is not go module"
135+
136+
govet:
137+
# Enable all analyzers.
138+
# Default: false
139+
enable-all: true
140+
# Disable analyzers by name.
141+
# Run `go tool vet help` to see all analyzers.
142+
# Default: []
143+
disable:
144+
- fieldalignment # too strict
145+
# Settings per analyzer.
146+
settings:
147+
shadow:
148+
# Whether to be strict about shadowing; can be noisy.
149+
# Default: false
150+
strict: true
151+
152+
nakedret:
153+
# Make an issue if func has more lines of code than this setting, and it has naked returns.
154+
# Default: 30
155+
max-func-lines: 0
156+
157+
nolintlint:
158+
# Exclude following linters from requiring an explanation.
159+
# Default: []
160+
allow-no-explanation: [ funlen, gocognit, lll ]
161+
# Enable to require an explanation of nonzero length after each nolint directive.
162+
# Default: false
163+
require-explanation: true
164+
# Enable to require nolint directives to mention the specific linter being suppressed.
165+
# Default: false
166+
require-specific: true
167+
168+
rowserrcheck:
169+
# database/sql is always checked
170+
# Default: []
171+
packages:
172+
- github.com/jmoiron/sqlx
173+
174+
tenv:
175+
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
176+
# Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
177+
# Default: false
178+
all: true
179+
180+
181+
linters:
182+
disable-all: true
183+
enable:
184+
## enabled by default
185+
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
186+
- gosimple # specializes in simplifying a code
187+
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
188+
- ineffassign # detects when assignments to existing variables are not used
189+
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
190+
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
191+
- unused # checks for unused constants, variables, functions and types
192+
## disabled by default
193+
- asasalint # checks for pass []any as any in variadic func(...any)
194+
- asciicheck # checks that your code does not contain non-ASCII identifiers
195+
- bidichk # checks for dangerous unicode character sequences
196+
- bodyclose # checks whether HTTP response body is closed successfully
197+
- cyclop # checks function and package cyclomatic complexity
198+
- dupl # tool for code clone detection
199+
- durationcheck # checks for two durations multiplied together
200+
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
201+
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
202+
- exhaustive # checks exhaustiveness of enum switch statements
203+
- exportloopref # checks for pointers to enclosing loop variables
204+
- forbidigo # forbids identifiers
205+
- funlen # tool for detection of long functions
206+
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
207+
- gochecknoglobals # checks that no global variables exist
208+
- gochecknoinits # checks that no init functions are present in Go code
209+
- gocognit # computes and checks the cognitive complexity of functions
210+
- goconst # finds repeated strings that could be replaced by a constant
211+
- gocritic # provides diagnostics that check for bugs, performance and style issues
212+
- gocyclo # computes and checks the cyclomatic complexity of functions
213+
- godot # checks if comments end in a period
214+
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
215+
# - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod //TODO: re-enable
216+
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
217+
- goprintffuncname # checks that printf-like functions are named with f at the end
218+
- gosec # inspects source code for security problems
219+
- lll # reports long lines
220+
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
221+
- makezero # finds slice declarations with non-zero initial length
222+
- mnd # detects magic numbers
223+
- musttag # enforces field tags in (un)marshaled structs
224+
- nakedret # finds naked returns in functions greater than a specified function length
225+
- nestif # reports deeply nested if statements
226+
- nilerr # finds the code that returns nil even if it checks that the error is not nil
227+
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
228+
- noctx # finds sending http request without context.Context
229+
- nolintlint # reports ill-formed or insufficient nolint directives
230+
- nonamedreturns # reports all named returns
231+
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
232+
- predeclared # finds code that shadows one of Go's predeclared identifiers
233+
- promlinter # checks Prometheus metrics naming via promlint
234+
- reassign # checks that package variables are not reassigned
235+
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
236+
- rowserrcheck # checks whether Err of rows is checked successfully
237+
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
238+
- stylecheck # is a replacement for golint
239+
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
240+
- testableexamples # checks if examples are testable (have an expected output)
241+
- testpackage # makes you use a separate _test package
242+
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
243+
- unconvert # removes unnecessary type conversions
244+
- unparam # reports unused function parameters
245+
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
246+
- wastedassign # finds wasted assignment statements
247+
- whitespace # detects leading and trailing whitespace
248+
249+
## you may want to enable
250+
#- decorder # checks declaration order and count of types, constants, variables and functions
251+
#- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized
252+
#- gci # controls golang package import order and makes it always deterministic
253+
#- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
254+
#- godox # detects FIXME, TODO and other comment keywords
255+
#- goheader # checks is file header matches to pattern
256+
#- interfacebloat # checks the number of methods inside an interface
257+
#- ireturn # accept interfaces, return concrete types
258+
#- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
259+
#- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
260+
#- wrapcheck # checks that errors returned from external packages are wrapped
261+
262+
## disabled
263+
#- containedctx # detects struct contained context.Context field
264+
#- contextcheck # [too many false positives] checks the function whether use a non-inherited context
265+
#- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
266+
#- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
267+
#- dupword # [useless without config] checks for duplicate words in the source code
268+
#- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/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
269+
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
270+
#- goerr113 # [too strict] checks the errors handling expressions
271+
#- gofmt # [replaced by goimports] checks whether code was gofmt-ed
272+
#- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
273+
#- grouper # analyzes expression groups
274+
#- importas # enforces consistent import aliases
275+
#- maintidx # measures the maintainability index of each function
276+
#- misspell # [useless] finds commonly misspelled English words in comments
277+
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
278+
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
279+
#- tagliatelle # checks the struct tags
280+
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
281+
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
282+
283+
## deprecated
284+
#- deadcode # [deprecated, replaced by unused] finds unused code
285+
#- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized
286+
#- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
287+
#- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible
288+
#- interfacer # [deprecated] suggests narrower interface types
289+
#- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted
290+
#- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name
291+
#- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs
292+
#- structcheck # [deprecated, replaced by unused] finds unused struct fields
293+
#- varcheck # [deprecated, replaced by unused] finds unused global variables and constants
294+
295+
296+
issues:
297+
# Maximum count of issues with the same text.
298+
# Set to 0 to disable.
299+
# Default: 3
300+
max-same-issues: 50
301+
302+
exclude-rules:
303+
- source: "^//\\s*go:generate\\s"
304+
linters: [ lll ]
305+
- source: "(noinspection|TODO)"
306+
linters: [ godot ]
307+
- source: "//noinspection"
308+
linters: [ gocritic ]
309+
- source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {"
310+
linters: [ errorlint ]
311+
- path: "internal\\/test\\/.*\\.go"
312+
linters:
313+
- goconst
314+
- path: "_test\\.go"
315+
linters:
316+
- bodyclose
317+
- dupl
318+
- funlen
319+
- goconst
320+
- gosec
321+
- noctx
322+
- revive
323+
- typecheck
324+
- wrapcheck
325+
output:
326+
formats:
327+
- format: colored-line-number

0 commit comments

Comments
 (0)