Skip to content

Commit 28267ef

Browse files
committed
feat: create 10-cautious
This ruleset is a cautious approach to the dependencies and the code quality. Compared to 03-safe: - add depguard to maintain the dependencies - add revive rules - atomic - comment-spacings - defer - early-return - if-return - useless-break
1 parent 42df05b commit 28267ef

File tree

3 files changed

+412
-0
lines changed

3 files changed

+412
-0
lines changed

10-cautious/.golangci.yml

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
---
2+
# golangci-lint configuration file made by @ccoVeille
3+
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
4+
# Author: @ccoVeille
5+
# License: MIT
6+
# Variant: 10-cautious
7+
# Version: v1.2.0
8+
#
9+
linters:
10+
# some linters are enabled by default
11+
# https://golangci-lint.run/usage/linters/
12+
#
13+
# enable some extra linters
14+
enable:
15+
# Errcheck is a program for checking for unchecked errors in Go code.
16+
- errcheck
17+
18+
# Linter for Go source code that specializes in simplifying code.
19+
- gosimple
20+
21+
# Vet examines Go source code and reports suspicious constructs.
22+
- govet
23+
24+
# Detects when assignments to existing variables are not used.
25+
- ineffassign
26+
27+
# It's a set of rules from staticcheck. See https://staticcheck.io/
28+
- staticcheck
29+
30+
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
31+
# Drop-in replacement of golint.
32+
- revive
33+
34+
# check imports order and makes it always deterministic.
35+
- gci
36+
37+
# make sure to use t.Helper() when needed
38+
- thelper
39+
40+
# mirror suggests rewrites to avoid unnecessary []byte/string conversion
41+
- mirror
42+
43+
# detect the possibility to use variables/constants from the Go standard library.
44+
- usestdlibvars
45+
46+
# Finds commonly misspelled English words.
47+
- misspell
48+
49+
# Checks for duplicate words in the source code.
50+
- dupword
51+
52+
# linter to detect errors invalid key values count
53+
- loggercheck
54+
55+
# detects nested contexts in loops or function literals
56+
- fatcontext
57+
58+
# checks if package imports are in a list of acceptable packages.
59+
- depguard
60+
61+
linters-settings:
62+
gci: # define the section orders for imports
63+
sections:
64+
# Standard section: captures all standard packages.
65+
- standard
66+
# Default section: catchall that is not standard or custom
67+
- default
68+
# linters that related to local tool, so they should be separated
69+
- localmodule
70+
71+
revive:
72+
rules:
73+
# Check for commonly mistaken usages of the sync/atomic package
74+
- name: atomic
75+
76+
# Blank import should be only in a main or test package, or have a comment justifying it.
77+
- name: blank-imports
78+
79+
# Spots comments not starting with a space
80+
- name: comment-spacings
81+
82+
# context.Context() should be the first parameter of a function when provided as argument.
83+
- name: context-as-argument
84+
arguments:
85+
- allowTypesBefore: "*testing.T"
86+
87+
# Basic types should not be used as a key in `context.WithValue`
88+
- name: context-keys-type
89+
90+
# warns on some common mistakes when using defer statement.
91+
- name: defer
92+
93+
# Importing with `.` makes the programs much harder to understand
94+
- name: dot-imports
95+
96+
# suggest to simplify if-then-else constructions when possible
97+
- name: early-return
98+
99+
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
100+
- name: empty-block
101+
102+
# for better readability, variables of type `error` must be named with the prefix `err`.
103+
- name: error-naming
104+
105+
# for better readability, the errors should be last in the list of returned values by a function.
106+
- name: error-return
107+
108+
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
109+
- name: error-strings
110+
111+
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
112+
- name: errorf
113+
114+
# Checking if an error is nil to just after return the error or nil is redundant.
115+
- name: if-return
116+
117+
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
118+
- name: increment-decrement
119+
120+
# highlights redundant else-blocks that can be eliminated from the code
121+
- name: indent-error-flow
122+
123+
# This rule suggests a shorter way of writing ranges that do not use the second value.
124+
- name: range
125+
126+
# receiver names in a method should reflect the struct name (p for Person, for example)
127+
- name: receiver-naming
128+
129+
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
130+
- name: redefines-builtin-id
131+
132+
# redundant else-blocks that can be eliminated from the code.
133+
- name: superfluous-else
134+
135+
# prevent confusing name for variables when using `time` package
136+
- name: time-naming
137+
138+
# warns when an exported function or method returns a value of an un-exported type.
139+
- name: unexported-return
140+
141+
# spots and proposes to remove unreachable code. also helps to spot errors
142+
- name: unreachable-code
143+
144+
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
145+
- name: unused-parameter
146+
147+
# warns on useless break statements in case clauses of switch and select statements
148+
- name: useless-break
149+
150+
# report when a variable declaration can be simplified
151+
- name: var-declaration
152+
153+
# warns when initialism, variable or package naming conventions are not followed.
154+
- name: var-naming
155+
156+
depguard:
157+
rules:
158+
obsolete:
159+
deny:
160+
- pkg: "golang.org/x/net/context"
161+
desc: "Should be replaced by standard lib context package (Go 1.7+)"
162+
163+
- pkg: "github.com/pkg/errors"
164+
desc: "Should be replaced by standard lib errors package (Go 1.13+)"
165+
166+
- pkg: "golang.org/x/xerrors"
167+
desc: "Should be replaced by standard lib errors package (Go 1.13+)"
168+
169+
- pkg: github.com/go-errors/errors
170+
desc: "Should be replaced by standard lib errors package"
171+
172+
- pkg: "io/ioutil"
173+
desc: "Should be replaced by standard lib os package (Go 1.16+)"
174+
175+
- pkg: "golang.org/x/exp/slices"
176+
desc: "Should be replaced by slices (Go 1.21+)"
177+
178+
- pkg: "golang.org/x/exp/maps"
179+
desc: "Should be replaced by standard lib maps package (Go 1.21+)"
180+
181+
- pkg: "math/rand$"
182+
desc: "Should be replaced by standard lib math/rand/v2 package (Go 1.23+)"
183+
184+
- pkg: "golang.org/x/syscall"
185+
desc: "Should be replaced by golang.org/x/sys or os package according to Go maintainers. More information: https://golang.org/s/go1.4-syscall"
186+
187+
- pkg: "golang.org/x/crypto/ed25519"
188+
desc: "Should be replaced by standard lib crypto/ed25519 package"
189+
190+
- pkg: "github.com/golang/protobuf"
191+
desc: "Should be replaced by google.golang.org/protobuf package (github.com/golang/protobuf is deprecated)"
192+
193+
- pkg: "github.com/gogo/protobuf"
194+
desc: "Should be replaced by google.golang.org/protobuf package (github.com/gogo/protobuf is deprecated)"
195+
196+
- pkg: "github.com/golang/protobuf/proto"
197+
desc: "Should be replaced by google.golang.org/protobuf/proto package (github.com/golang/protobuf/proto is deprecated)"
198+
199+
- pkg: "github.com/gogo/status"
200+
desc: "Should be replaced by google.golang.org/grpc/status package (github.com/gogo/status is deprecated)"
201+
202+
logs:
203+
deny:
204+
- pkg: "github.com/prometheus/common/log"
205+
desc: "Could be replaced by standard lib log/slog package"
206+
207+
- pkg: "github.com/sirupsen/logrus"
208+
desc: "Should be replaced by standard lib log/slog package"
209+
210+
- pkg: github.com/siddontang/go-log/log
211+
desc: "Could be replaced by standard lib log/slog package"
212+
213+
- pkg: github.com/siddontang/go/log
214+
desc: "Could be replaced by standard lib log/slog package"
215+
216+
- pkg: github.com/mailgun/log
217+
desc: "Could be replaced by standard lib log/slog package"
218+
219+
- pkg: github.com/saferwall/pe/log
220+
desc: "Could be replaced by standard lib log/slog package"
221+
222+
recommended:
223+
deny:
224+
- pkg: "go.uber.org/atomic"
225+
desc: "Could be replaced by standard lib sync/atomic package"
226+
227+
- pkg: "github.com/hashicorp/go-multierror"
228+
desc: "Could be replaced by errors.Join (Go 1.20+)"
229+
230+
forbidigo:
231+
forbid:
232+
# this one could be moved to ldez/exptostd
233+
- p: "constraints\\.Ordered"
234+
msg: "Use standard lib cmp.Ordered instead (Go 1.21+)"
235+
236+
# doesn't work ?
237+
- pkg: "^golang.org/x/exp/constraints$"
238+
p: "^.*$"
239+
msg: "WIP"
240+
241+
- p: ^atomic\.(Add|CompareAndSwap|Load|Store|Swap).
242+
msg: Go 1.19 atomic types should be used instead.
243+
dupword:
244+
# Keywords used to ignore detection.
245+
# Default: []
246+
ignore: []
247+
# - "blah" # this will accept "blah blah …" as a valid duplicate word
248+
249+
misspell:
250+
# Correct spellings using locale preferences for US or UK.
251+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
252+
# Default ("") is to use a neutral variety of English.
253+
locale: US
254+
255+
# List of words to ignore
256+
# among the one defined in https://github.com/golangci/misspell/blob/master/words.go
257+
ignore-words: []
258+
# - valor
259+
# - and
260+
261+
# Extra word corrections.
262+
extra-words: []
263+
# - typo: "whattever"
264+
# correction: "whatever"

0 commit comments

Comments
 (0)