Skip to content

Commit e8b9e0a

Browse files
authored
introduce stricter linter configuration #1169 (#1170)
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 991cb3a commit e8b9e0a

File tree

116 files changed

+785
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+785
-543
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
go-version-file: "go.mod"
2626
cache: false
2727
- name: golangci-lint
28-
uses: golangci/golangci-lint-action@v7
28+
uses: golangci/golangci-lint-action@v8
2929
with:
30-
version: v2.0
30+
version: v2.1
3131
args: --timeout=30m

.golangci.yml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
# - containedctx
5+
# - contextcheck
6+
# - depguard
7+
# - dupl
8+
# - errname
9+
- errorlint
10+
# - fatcontext
11+
# - forcetypeassert
12+
- ginkgolinter
13+
# - gocognit
14+
# - goconst
15+
# - gocritic
16+
# - godot
17+
# - gosec
18+
# - intrange
19+
# - ireturn
20+
# - lll
21+
# - maintidx
22+
- mirror
23+
- misspell
24+
- nilerr
25+
- nilnesserr
26+
- nolintlint
27+
# - paralleltest
28+
# - prealloc
29+
# - promlinter
30+
# - revive
31+
# - rowserrcheck
32+
# - sqlclosecheck
33+
# - testifylint
34+
- thelper
35+
- unconvert
36+
# - unparam
37+
- usetesting
38+
- wastedassign
39+
- whitespace
40+
- govet
41+
# - staticcheck
42+
- canonicalheader
43+
# - copyloopvar
44+
- dupword
45+
# - err113
46+
- exptostd
47+
- goheader
48+
- importas
49+
# - intrange
50+
- nakedret
51+
- sloglint
52+
- usestdlibvars
53+
# wrapcheck is not working as expected. It is categorizing internal packages as external.
54+
#- wrapcheck
55+
settings:
56+
depguard:
57+
rules:
58+
main:
59+
deny:
60+
- pkg: github.com/pkg/errors
61+
desc: github.com/pkg/errors is no longer maintained
62+
errcheck:
63+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
64+
# Such cases aren't reported by default.
65+
# Default: false
66+
check-type-assertions: false
67+
errorlint:
68+
# Check whether fmt.Errorf uses the %w verb for formatting errors.
69+
# See the https://github.com/polyfloyd/go-errorlint for caveats.
70+
# Default: true
71+
errorf: true
72+
# Check for plain type assertions and type switches.
73+
# Default: true
74+
asserts: false
75+
# Check for plain error comparisons.
76+
# Default: true
77+
comparison: true
78+
fatcontext:
79+
check-struct-pointers: true
80+
gocognit:
81+
min-complexity: 15
82+
gosec:
83+
excludes:
84+
- G204
85+
- G404
86+
- G306
87+
govet:
88+
disable:
89+
- fieldalignment
90+
# Enable all analyzers.
91+
# Default: false
92+
enable-all: false
93+
iface:
94+
enable:
95+
- identical # Identifies interfaces in the same package that have identical method sets.
96+
- unused # Identifies interfaces that are not used anywhere in the same package where the interface is defined.
97+
- opaque # Identifies functions that return interfaces, but the actual returned value is always a single concrete implementation.
98+
ireturn:
99+
# By default, it allows using errors, empty interfaces, anonymous interfaces,
100+
# and interfaces provided by the standard library.
101+
allow:
102+
- error
103+
- empty
104+
- anon
105+
- stdlib
106+
- generic
107+
- (or|er)$
108+
- T
109+
- github.com/prometheus/client_golang/prometheus.Counter
110+
- github.com/prometheus/client_golang/prometheus.Gauge
111+
- github.com/prometheus/client_golang/prometheus.Histogram
112+
lll:
113+
# Max line length, lines longer will be reported.
114+
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
115+
# Default: 120.
116+
line-length: 240
117+
maintidx:
118+
under: 20
119+
nolintlint:
120+
require-specific: true
121+
revive:
122+
enable-all-rules: true
123+
rules:
124+
- name: argument-limit
125+
arguments:
126+
- 5
127+
- name: line-length-limit
128+
arguments:
129+
- 240
130+
- name: file-header
131+
disabled: true
132+
- name: package-comments
133+
disabled: true
134+
- name: max-public-structs
135+
disabled: true
136+
- name: banned-characters
137+
disabled: true
138+
- name: cognitive-complexity
139+
disabled: true
140+
- name: cyclomatic
141+
disabled: true
142+
- name: function-length
143+
disabled: true
144+
- name: function-result-limit
145+
arguments:
146+
- 3
147+
- name: add-constant
148+
disabled: true
149+
- name: unhandled-error
150+
arguments:
151+
- fmt.Printf
152+
- fmt.Println
153+
- name: confusing-naming
154+
disabled: true
155+
- name: comment-spacings
156+
arguments:
157+
- 'nolint:'
158+
rowserrcheck:
159+
packages:
160+
- github.com/jackc/pgx/v5
161+
- github.com/jackc/pgx/v4
162+
wrapcheck:
163+
# An array of strings specifying additional substrings of signatures to ignore.
164+
# Unlike 'ignoreSigs', this option extends the default set (or the set specified in 'ignoreSigs') without replacing it entirely.
165+
# This allows you to add specific signatures to the ignore list
166+
# while retaining the defaults or any items in 'ignoreSigs'.
167+
# Default: []
168+
extra-ignore-sigs:
169+
- .CustomError(
170+
- .SpecificWrap(
171+
172+
# An array of strings that specify substrings of signatures to ignore.
173+
# If this set, it will override the default set of ignored signatures.
174+
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
175+
# Default: [".Errorf(", "errors.New(", "errors.Unwrap(", "errors.Join(", ".Wrap(", ".Wrapf(", ".WithMessage(", ".WithMessagef(", ".WithStack("]
176+
ignore-sigs:
177+
- errors.New(
178+
- errors.Newf(
179+
- errors.Unwrap(
180+
- errors.Join(
181+
- .Wrap(
182+
- .Wrapf(
183+
- status.Error(
184+
- .Wait() # The error reported by errorgroup.Wait() (external) actually
185+
# originates from the internal code.
186+
# An array of strings that specify regular expressions of signatures to ignore.
187+
# Default: []
188+
ignore-sig-regexps:
189+
- \.New.*Error\(
190+
# An array of strings that specify globs of packages to ignore.
191+
# Default: []
192+
ignore-package-globs:
193+
- github.ibm.com/decentralized-trust-research/scalable-committer/utils/grpcerror
194+
# An array of strings that specify regular expressions of interfaces to ignore.
195+
# Default: []
196+
# ignoreInterfaceRegexps:
197+
# - ^(?i)c(?-i)ach(ing|e)
198+
exclusions:
199+
# Mode of the generated files analysis.
200+
#
201+
# - `strict`: sources are excluded by strictly following the Go generated file convention.
202+
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
203+
# This line must appear before the first non-comment, non-blank text in the file.
204+
# https://go.dev/s/generatedcode
205+
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
206+
# - `disable`: disable the generated files exclusion.
207+
#
208+
# Default: lax
209+
generated: lax
210+
# Log a warning if an exclusion rule is unused.
211+
# Default: false
212+
warn-unused: true
213+
# Predefined exclusion rules.
214+
# Default: []
215+
presets:
216+
- common-false-positives
217+
#formatters:
218+
# enable:
219+
# - gofumpt
220+
# - goimports
221+
# settings:
222+
# gofumpt:
223+
# extra-rules: true
224+
# goimports:
225+
# # A comma-separated list of prefixes, which, if set, checks import paths
226+
# # with the given prefixes are grouped after 3rd-party packages.
227+
# # Default: ""
228+
# local-prefixes:
229+
# - github.ibm.com/decentralized-trust-research/idap
230+
# exclusions:
231+
# generated: lax

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ lint:
145145
@echo "Running Go Linters..."
146146
golangci-lint run --color=always --timeout=4m
147147

148+
.PHONY: lint-auto-fix
149+
lint-auto-fix:
150+
@echo "Running Go Linters with auto-fix..."
151+
golangci-lint run --color=always --timeout=4m --fix
152+
148153
.PHONY: install-linter-tool
149154
install-linter-tool:
150155
@echo "Installing golangci Linter"

checks.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ govet:
4141
misspell:
4242
@echo Running misspell
4343
@{ \
44-
OUTPUT="$$(misspell . || true)"; \
44+
OUTPUT="$$(find . -type f | grep -v '.golangci.yml' | xargs misspell || true)"; \
4545
if [ -n "$$OUTPUT" ]; then \
4646
echo "The following files are have spelling errors:"; \
4747
echo "$$OUTPUT"; \

cmd/tokengen/main_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ func TestGenFullSuccess(t *testing.T) {
3737
gt.Expect(err).NotTo(HaveOccurred())
3838
defer gexec.CleanupBuildArtifacts()
3939

40-
tempOutput, err := os.MkdirTemp("", "tokengen-test")
41-
gt.Expect(err).NotTo(HaveOccurred())
40+
tempOutput := t.TempDir()
4241
defer utils.IgnoreErrorWithOneArg(os.RemoveAll, tempOutput)
4342

4443
testGenRun(
@@ -73,8 +72,7 @@ func TestFullUpdate(t *testing.T) {
7372
gt.Expect(err).NotTo(HaveOccurred())
7473
defer gexec.CleanupBuildArtifacts()
7574

76-
tempOutput, err := os.MkdirTemp("", "tokengen-update-test")
77-
gt.Expect(err).NotTo(HaveOccurred())
75+
tempOutput := t.TempDir()
7876
defer utils.IgnoreErrorWithOneArg(os.RemoveAll, tempOutput)
7977

8078
// Switching the auditor and issuer certs to test the update function
@@ -110,8 +108,7 @@ func TestPartialUpdate(t *testing.T) {
110108
gt.Expect(err).NotTo(HaveOccurred())
111109
defer gexec.CleanupBuildArtifacts()
112110

113-
tempOutput, err := os.MkdirTemp("", "tokengen-update-test")
114-
gt.Expect(err).NotTo(HaveOccurred())
111+
tempOutput := t.TempDir()
115112
defer utils.IgnoreErrorWithOneArg(os.RemoveAll, tempOutput)
116113

117114
// Only changing the issuer cert to also use the auditor cert.

integration/nwo/token/common/ca.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (i *IdemixCASupport) Gen(owner string) (res token.IdentityConfiguration, er
215215
cmd := common.NewCommand(fabricCAClientExePath, registerCommand)
216216
sess, err := i.StartSession(cmd, registerCommand.SessionName())
217217
if err != nil {
218-
return
218+
return res, err
219219
}
220220
gomega.Eventually(sess, i.EventuallyTimeout).Should(gexec.Exit(0))
221221

@@ -230,13 +230,13 @@ func (i *IdemixCASupport) Gen(owner string) (res token.IdentityConfiguration, er
230230
cmd = common.NewCommand(fabricCAClientExePath, enrollCommand)
231231
sess, err = i.StartSession(cmd, enrollCommand.SessionName())
232232
if err != nil {
233-
return
233+
return res, err
234234
}
235235
gomega.Eventually(sess, i.EventuallyTimeout).Should(gexec.Exit(0))
236236

237237
res.ID = owner
238238
res.URL = userOutput
239-
return
239+
return res, err
240240
}
241241

242242
func (i *IdemixCASupport) GenerateConfiguration() error {

integration/nwo/token/generators/fabtoken/fabtoken.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ func (d *CryptoMaterialGenerator) Generate(tms *topology.TMS, n *node.Node, wall
231231
identities = append(identities, id)
232232
}
233233
return identities
234-
235234
}
236235

237236
func (d *CryptoMaterialGenerator) GenerateCryptoConfig(output string, layout *Layout) {

integration/nwo/txgen/model/distribution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (d *Distribution) GetAmounts(total api.Amount) ([]api.Amount, api.Error) {
2525
}
2626

2727
msg := fmt.Sprintf("Unknown type in distribution: %s", *d)
28-
//logging.Logger.Errorf(msg)
28+
// logging.Logger.Errorf(msg)
2929

3030
return nil, api.NewBadRequestError(nil, msg)
3131
}
@@ -92,7 +92,7 @@ func (d *Distribution) convertToIntegers(input []string) ([]api.Amount, api.Erro
9292
num, err := strconv.Atoi(v)
9393
if err != nil {
9494
msg := fmt.Sprintf("Can't convert %s to intereger", v)
95-
//logging.Logger.Errorf(msg)
95+
// logging.Logger.Errorf(msg)
9696
return nil, api.NewBadRequestError(nil, msg)
9797
}
9898
ints[i] = api.Amount(num)

integration/nwo/txgen/service/config/reader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func Load() (*model.Configuration, api.Error) {
5050
err := viper.Unmarshal(&config)
5151
if err != nil {
5252
appErr := api.NewInternalServerError(
53-
fmt.Errorf("cannot unmarshal the configuration file: %s", err),
53+
fmt.Errorf("cannot unmarshal the configuration file: %w", err),
5454
"Internal Server Error",
5555
)
5656
return nil, appErr
@@ -69,7 +69,7 @@ func loadConfig(configFile string) api.Error {
6969
err := viper.MergeInConfig()
7070
if err != nil {
7171
return api.NewInternalServerError(
72-
fmt.Errorf("couldn't read the config file '%s': %s", configFile, err),
72+
fmt.Errorf("couldn't read the config file '%s': %w", configFile, err),
7373
"Internal Server Error",
7474
)
7575
}
@@ -82,7 +82,7 @@ func loadDefaultConfig() api.Error {
8282
configuration, err := embeddedFiles.ReadFile("config.yaml")
8383
if err != nil {
8484
return api.NewInternalServerError(
85-
fmt.Errorf("couldn't find the default config file 'config.yaml': %s", err),
85+
fmt.Errorf("couldn't find the default config file 'config.yaml': %w", err),
8686
"Internal Server Error",
8787
)
8888
}
@@ -92,7 +92,7 @@ func loadDefaultConfig() api.Error {
9292
err = viper.ReadConfig(bytes.NewReader(configuration))
9393
if err != nil {
9494
return api.NewInternalServerError(
95-
fmt.Errorf("couldn't read the default config file 'config.yaml': %s", err),
95+
fmt.Errorf("couldn't read the default config file 'config.yaml': %w", err),
9696
"Internal Server Error",
9797
)
9898
}

integration/nwo/txgen/service/metrics/provider.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func (h *histogram) Observe(v float64) {
5757
h.sum += v
5858
h.n++
5959
})
60-
6160
}
6261
func (h *histogram) Min() float64 { return h.min }
6362
func (h *histogram) Max() float64 { return h.max }

0 commit comments

Comments
 (0)