Skip to content

Commit 6aad113

Browse files
feat(golangcilint): bump golangci-lint to v2
1 parent 9ef0298 commit 6aad113

File tree

4 files changed

+123
-140
lines changed

4 files changed

+123
-140
lines changed

internal/codegen/imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func importPathToAssumedName(importPath string) string {
9999
}
100100
base = strings.TrimPrefix(base, "go-")
101101
if i := strings.IndexFunc(base, func(r rune) bool {
102+
//nolint:staticcheck // De Morgan's law intentionally not applied
102103
return !('a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || '0' <= r && r <= '9' || r == '_' ||
103104
r >= utf8.RuneSelf && (unicode.IsLetter(r) || unicode.IsDigit(r)))
104105
}); i >= 0 {

tools/sgartifactregistry/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ func NpmAuthenticate(ctx context.Context, packageJSONDir, registryURL string) er
5757
yarnMajor = strings.Split(version, ".")[0]
5858
}
5959

60-
switch {
60+
switch yarnMajor {
6161
// If yarn v1 or npm we use npm config
62-
case yarnMajor == "1":
62+
case "1":
6363
cmd = sg.Command(
6464
ctx,
6565
"npm",

tools/sggolangcilint/golangci.yml

Lines changed: 118 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
version: "2"
2+
13
run:
2-
timeout: 10m
34
build-tags:
45
- wireinject
6+
relative-path-mode: gomod
57

68
issues:
79
fix: false
8-
exclude-dirs:
9-
- .git
10-
- node_modules
1110

1211
linters:
13-
disable-all: true
12+
default: none
1413
enable:
14+
# Check for pass []any as any in variadic func(...any).
15+
# [fast: false, auto-fix: false]
16+
- asasalint
17+
1518
# Check that code does not contain non-ASCII identifiers.
1619
# [fast: true, auto-fix: false]
1720
- asciicheck
1821

22+
# Checks for dangerous unicode character sequences.
23+
# [fast: true]
24+
- bidichk
25+
1926
# Check whether HTTP response body is closed successfully.
2027
# [fast: false, auto-fix: false]
2128
- bodyclose
@@ -32,6 +39,10 @@ linters:
3239
# [fast: false, auto-fix: false]
3340
- errcheck
3441

42+
# Checks types passed to the json encoding functions. Reports unsupported types and reports occurrences where the check for the returned error can be omitted.
43+
# [fast: false, autofix: false]
44+
- errchkjson
45+
3546
# Check that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
3647
# [fast: false, auto-fix: false]
3748
- errname
@@ -44,9 +55,9 @@ linters:
4455
# [fast: ?, auto-fix: true]
4556
- exptostd
4657

47-
# Check package import order and make it always deterministic.
48-
# [fast: true, auto-fix: true]
49-
- gci
58+
# Check that no global variables exist.
59+
# [fast: false, auto-fix: false]
60+
- gochecknoglobals
5061

5162
# Check that no init functions are present in Go code.
5263
# [fast: true, auto-fix: false]
@@ -60,10 +71,6 @@ linters:
6071
# [fast: true, auto-fix: true]
6172
- godot
6273

63-
# Check whether code was gofumpt-ed.
64-
# [fast: true, auto-fix: true]
65-
- gofumpt
66-
6774
# Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
6875
# [fast: true, auto-fix: false]
6976
- gomoddirectives
@@ -76,9 +83,9 @@ linters:
7683
# [fast: true, auto-fix: false]
7784
- goprintffuncname
7885

79-
# Check for code that can be simplified.
86+
# Inspects source code for security problems.
8087
# [fast: false, auto-fix: false]
81-
- gosimple
88+
- gosec
8289

8390
# Report suspicious constructs, such as Printf calls whose arguments do not align with the format string.
8491
# [fast: false, auto-fix: false]
@@ -108,6 +115,10 @@ linters:
108115
# [fast: false, auto-fix: false]
109116
- nilerr
110117

118+
# Finds sending http request without context.Context.
119+
# [fast: false, auto-fix: false]
120+
- noctx
121+
111122
# Report ill-formed or insufficient nolint directives.
112123
# [fast: true, auto-fix: false]
113124
- nolintlint
@@ -128,10 +139,22 @@ linters:
128139
# [fast: false, auto-fix: true]
129140
- protogetter
130141

142+
# Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
143+
# [fast: false, auto-fix: true]
144+
- revive
145+
131146
# Check whether Err of rows is checked successfully.
132147
# [fast: false, auto-fix: false]
133148
- rowserrcheck
134149

150+
# Ensure consistent code style when using log/slog.
151+
# [fast: false, auto-fix: false]
152+
- sloglint
153+
154+
# Checks for mistakes with OpenTelemetry/Census spans.
155+
# [fast: false, auto-fix: false]
156+
- spancheck
157+
135158
# Check that sql.Rows and sql.Stmt are closed.
136159
# [fast: false, auto-fix: false]
137160
- sqlclosecheck
@@ -140,18 +163,10 @@ linters:
140163
# [fast: false, auto-fix: false]
141164
- staticcheck
142165

143-
# A replacement for golint.
144-
# [fast: false, auto-fix: false]
145-
- stylecheck
146-
147166
# Detect inappropriate usage of t.Parallel() method in your Go test codes.
148167
# [fast: false, auto-fix: false]
149168
- tparallel
150169

151-
# Parses and type-checks Go code.
152-
# [fast: false, auto-fix: false]
153-
- typecheck
154-
155170
# Remove unnecessary type conversions.
156171
# [fast: false, auto-fix: false]
157172
- unconvert
@@ -160,120 +175,91 @@ linters:
160175
# [fast: false, auto-fix: false]
161176
- unused
162177

178+
# A linter that detect the possibility to use variables/constants from the Go standard library.
179+
# [fast: true, auto-fix: true]
180+
- usestdlibvars
181+
163182
# Find wasted assignment statements.
164183
# [fast: false, auto-fix: false]
165184
- wastedassign
166185

167186
# Detect leading and trailing whitespace.
168187
# [fast: true, auto-fix: true]
169188
- whitespace
170-
171-
# Check that no global variables exist.
172-
# [fast: true, auto-fix: false]
173-
- gochecknoglobals
174-
175-
# Inspect source code for security problems.
176-
# [fast: false, auto-fix: false]
177-
- gosec
178-
179-
# Find sending http request without context.Context.
180-
# [fast: false, auto-fix: false]
181-
- noctx
182-
183-
# Drop-in replacement of golint.
184-
# [fast: false, auto-fix: false]
185-
- revive
186-
187-
# Check for pass []any as any in variadic func(...any).
188-
# [fast: false, auto-fix: false]
189-
- asasalint
190-
191-
# Check for dangerous unicode character sequences.
192-
# [fast: true, auto-fix: false]
193-
- bidichk
194-
195-
# Check types passed to the json encoding functions.
196-
# [fast: false, auto-fix: false]
197-
- errchkjson
198-
199-
# Check for the possibility to use variables/constants from the Go standard library.
200-
# [fast: true, auto-fix: false]
201-
- usestdlibvars
202-
203-
# Checks for mistakes with OpenTelemetry/Census spans.
204-
# [fast: false, auto-fix: false]
205-
- spancheck
206-
207-
# Ensure consistent code style when using log/slog.
208-
- sloglint
209-
linters-settings:
210-
gomodguard:
211-
blocked:
212-
modules:
213-
- github.com/sirupsen/logrus:
214-
recommendations:
215-
- go.uber.org/zap
216-
reason: "Use Zap for logging."
217-
- github.com/rs/zerolog:
218-
recommendations:
219-
- go.uber.org/zap
220-
reason: "Use Zap for logging."
221-
- github.com/pkg/errors:
222-
recommendations:
223-
- errors
224-
- fmt
225-
reason: "Use the standard library error packages."
226-
- golang.org/x/xerrors:
227-
recommendations:
228-
- errors
229-
- fmt
230-
reason: "Use the standard library error packages."
231-
- github.com/golang/protobuf:
232-
recommendations:
233-
- google.golang.org/protobuf
234-
reason: "The protobuf v1 module is deprecated."
235-
- github.com/stretchr/testify:
236-
recommendations:
237-
- gotest.tools/v3
238-
reason: "More reliably supports protobuf messages."
239-
240-
gofumpt:
241-
extra-rules: true
242-
243-
gosec:
244-
excludes:
245-
# Flags for potentially-unsafe casting of ints. Prone to lots of false positives.
246-
- G115
247-
248-
lll:
249-
line-length: 120
250-
tab-width: 1
251-
252-
misspell:
253-
locale: US
254-
ignore-words:
255-
- cancelled
256-
- cancelling
257-
- analyses # allow analyses as a plural form of analysis
258-
259-
prealloc:
260-
simple: true
261-
range-loops: true
262-
for-loops: true
263-
264-
protogetter:
265-
skip-any-generated: true
266-
267-
staticcheck:
268-
checks: [all]
269-
270-
stylecheck:
271-
checks: [all]
272-
273-
errorlint:
274-
# Don't enforce %w to minimize implicit interface leakage.
275-
# https://github.com/dwmkerr/hacker-laws#hyrums-law-the-law-of-implicit-interfaces
276-
errorf: false
277-
278-
gomoddirectives:
279-
replace-local: true
189+
settings:
190+
errorlint:
191+
errorf: false
192+
193+
gomoddirectives:
194+
replace-local: true
195+
196+
gomodguard:
197+
blocked:
198+
modules:
199+
- github.com/sirupsen/logrus:
200+
recommendations:
201+
- go.uber.org/zap
202+
reason: Use Zap for logging.
203+
- github.com/rs/zerolog:
204+
recommendations:
205+
- go.uber.org/zap
206+
reason: Use Zap for logging.
207+
- github.com/pkg/errors:
208+
recommendations:
209+
- errors
210+
- fmt
211+
reason: Use the standard library error packages.
212+
- golang.org/x/xerrors:
213+
recommendations:
214+
- errors
215+
- fmt
216+
reason: Use the standard library error packages.
217+
- github.com/golang/protobuf:
218+
recommendations:
219+
- google.golang.org/protobuf
220+
reason: The protobuf v1 module is deprecated.
221+
- github.com/stretchr/testify:
222+
recommendations:
223+
- gotest.tools/v3
224+
reason: More reliably supports protobuf messages.
225+
226+
gosec:
227+
excludes:
228+
- G115
229+
230+
lll:
231+
line-length: 120
232+
tab-width: 1
233+
234+
misspell:
235+
locale: US
236+
ignore-rules:
237+
- cancelled
238+
- cancelling
239+
- analyses
240+
241+
prealloc:
242+
simple: true
243+
range-loops: true
244+
for-loops: true
245+
246+
protogetter:
247+
skip-any-generated: true
248+
249+
staticcheck:
250+
checks:
251+
- all
252+
253+
exclusions:
254+
generated: lax
255+
presets:
256+
- comments
257+
- common-false-positives
258+
- legacy
259+
- std-error-handling
260+
paths:
261+
- .git
262+
- node_modules
263+
- third_party$
264+
- builtin$
265+
- examples$

tools/sggolangcilint/tools.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
const (
1919
name = "golangci-lint"
20-
version = "1.64.8"
20+
version = "2.0.1"
2121
)
2222

2323
//go:embed golangci.yml
@@ -37,12 +37,8 @@ func CommandInDirectory(ctx context.Context, directory string, args ...string) *
3737
if _, err := os.Lstat(configPath); errors.Is(err, os.ErrNotExist) {
3838
configPath = defaultConfigPath()
3939
}
40-
var excludeArg []string
41-
if directory == sg.FromSageDir() {
42-
excludeArg = append(excludeArg, "--exclude", "(is a global variable|is unused)")
43-
}
4440
cmdArgs := append([]string{"run", "--allow-parallel-runners", "-c", configPath}, args...)
45-
cmd := Command(ctx, append(cmdArgs, excludeArg...)...)
41+
cmd := Command(ctx, cmdArgs...)
4642
cmd.Dir = directory
4743
return cmd
4844
}

0 commit comments

Comments
 (0)