Skip to content

Commit 39dd69d

Browse files
committed
feat: init project
1 parent 2ba3f71 commit 39dd69d

File tree

7 files changed

+786
-0
lines changed

7 files changed

+786
-0
lines changed

.golangci.yaml

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

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
################################################################################
2+
# Code Quality Targets
3+
################################################################################
4+
fmt:
5+
@go run mvdan.cc/gofumpt@latest -l -w .
6+
.PHONY: fmt
7+
8+
lint:
9+
@go run github.com/golangci/golangci-lint/cmd/[email protected] run --fix --timeout 5m
10+
.PHONY: lint
11+

0 commit comments

Comments
 (0)