Skip to content

Commit 63b0cac

Browse files
authored
Update golangci-lint to v2.0.2 (#299)
1 parent 464fb48 commit 63b0cac

File tree

4 files changed

+102
-139
lines changed

4 files changed

+102
-139
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.go text eol=lf

.github/workflows/golangci-lint.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,10 @@ jobs:
1414
golangci:
1515
strategy:
1616
matrix:
17-
include:
18-
- GOOS: windows
19-
- GOOS: linux
20-
- GOOS: darwin
17+
os: [ubuntu-latest, macos-latest, windows-latest]
2118
name: lint
22-
runs-on: ubuntu-latest
19+
runs-on: ${{ matrix.os }}
2320
steps:
24-
- name: Echo details
25-
env:
26-
GOOS: ${{ matrix.GOOS }}
27-
run: echo Go GOOS=$GOOS
28-
2921
- uses: actions/checkout@v3
3022

3123
# Uses Go version from the repository.
@@ -40,10 +32,10 @@ jobs:
4032
- name: golangci-lint
4133
env:
4234
GOOS: ${{ matrix.GOOS }}
43-
uses: golangci/golangci-lint-action@v3
35+
uses: golangci/golangci-lint-action@v7
4436
with:
4537
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
46-
version: v1.64.8
38+
version: v2.0.2
4739

4840
# Give the job more time to execute.
4941
# Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but,
@@ -52,10 +44,7 @@ jobs:
5244
# which can lead to some frustration from developers who would like to
5345
# fix a single line in an existing codebase and the linter would force them
5446
# into fixing all linting issues in the whole file instead
55-
args: --timeout=30m --whole-files --skip-dirs='helpers/windows'
56-
57-
# Optional: if set to true then the action will use pre-installed Go.
58-
skip-go-installation: true
47+
args: --timeout=30m --whole-files
5948

6049
# Optional: show only new issues if it's a pull request. The default value is `false`.
6150
only-new-issues: true

.golangci.yml

Lines changed: 95 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,100 @@
1-
# options for analysis running
2-
run:
3-
# timeout for analysis, e.g. 30s, 5m, default is 1m
4-
timeout: 1m
5-
go: "1.24.1"
6-
7-
issues:
8-
# Maximum count of issues with the same text.
9-
# Set to 0 to disable.
10-
# Default: 3
11-
max-same-issues: 0
12-
# Maximum issues count per one linter.
13-
# Set to 0 to disable.
14-
# Default: 50
15-
max-issues-per-linter: 0
16-
17-
output:
18-
sort-results: true
1+
version: "2"
192

203
# Find the whole list here https://golangci-lint.run/usage/linters/
214
linters:
22-
disable-all: true
5+
default: none
236
enable:
24-
- errcheck # checking for unchecked errors in go programs
25-
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
26-
- forbidigo # forbids identifiers matched by reg exps
27-
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
28-
- misspell # finds commonly misspelled English words in comments
29-
- nakedret # finds naked returns in functions greater than a specified function length
30-
- nolintlint # reports ill-formed or insufficient nolint directives
31-
- unused # checks Go code for unused constants, variables, functions and types
32-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
33-
- ineffassign # detects when assignments to existing variables are not used
34-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
35-
- asciicheck # simple linter to check that your code does not contain non-ASCII identifiers
36-
- bodyclose # checks whether HTTP response body is closed successfully
37-
- durationcheck # check for two durations multiplied together
38-
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
39-
- gosec # inspects source code for security problems
40-
- importas # enforces consistent import aliases
41-
- nilerr # finds the code that returns nil even if it checks that the error is not nil.
42-
- noctx # noctx finds sending http request without context.Context
43-
- unconvert # Remove unnecessary type conversions
44-
- wastedassign # wastedassign finds wasted assignment statements.
45-
- gomodguard # check for blocked dependencies in go.mod
46-
- depguard # check for blocked dependencies in Go files
47-
- copyloopvar
48-
49-
# all available settings of specific linters
50-
linters-settings:
51-
errcheck:
52-
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
53-
check-type-assertions: true
54-
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
55-
check-blank: false
56-
# List of functions to exclude from checking, where each entry is a single function to exclude.
57-
# See https://github.com/kisielk/errcheck#excluding-functions for details.
58-
exclude-functions:
59-
- (mapstr.M).Delete # Only returns ErrKeyNotFound, can safely be ignored.
60-
- (mapstr.M).Put # Can only fail on type conversions, usually safe to ignore.
61-
62-
errorlint:
63-
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
64-
errorf: true
65-
# Check for plain type assertions and type switches
66-
asserts: true
67-
# Check for plain error comparisons
68-
comparison: true
69-
70-
forbidigo:
71-
# Forbid the following identifiers
72-
forbid:
73-
- fmt.Print.* # too much log noise
74-
# Exclude godoc examples from forbidigo checks. Default is true.
75-
exclude_godoc_examples: true
76-
77-
gomoddirectives:
78-
# Allow local `replace` directives. Default is false.
79-
replace-local: false
80-
81-
nakedret:
82-
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
83-
max-func-lines: 0
84-
85-
nolintlint:
86-
# Enable to ensure that nolint directives are all used. Default is true.
87-
allow-unused: false
88-
# Disable to ensure that nolint directives don't have a leading space. Default is true.
89-
allow-leading-space: false
90-
# Exclude following linters from requiring an explanation. Default is [].
91-
allow-no-explanation: []
92-
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
93-
require-explanation: true
94-
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
95-
require-specific: true
96-
97-
gomodguard:
98-
blocked:
99-
# List of blocked modules.
100-
modules:
101-
# Blocked module.
102-
- github.com/pkg/errors:
103-
# Recommended modules that should be used instead. (Optional)
104-
recommendations:
105-
- errors
106-
- fmt
107-
reason: "This package is deprecated, use fmt.Errorf with %%w instead"
108-
- github.com/elastic/beats/v7:
109-
reason: "There must be no Beats dependency"
110-
111-
depguard:
112-
rules:
113-
main:
114-
list-mode: lax
115-
deny:
116-
- pkg: "math/rand$"
117-
desc: "superseded by math/rand/v2"
118-
119-
unused:
7+
- asciicheck
8+
- bodyclose
9+
- depguard
10+
- durationcheck
11+
- errcheck
12+
- errorlint
13+
- forbidigo
14+
- gomoddirectives
15+
- gomodguard
16+
- gosec
17+
- govet
18+
- importas
19+
- ineffassign
20+
- misspell
21+
- nakedret
22+
- nilerr
23+
- noctx
24+
- nolintlint
25+
- staticcheck
26+
- unconvert
27+
- unused
28+
- wastedassign
29+
settings:
30+
depguard:
31+
rules:
32+
main:
33+
list-mode: lax
34+
deny:
35+
- pkg: math/rand$
36+
desc: superseded by math/rand/v2
37+
errcheck:
38+
check-type-assertions: true
39+
check-blank: false
40+
exclude-functions:
41+
- (mapstr.M).Delete
42+
- (mapstr.M).Put
43+
errorlint:
44+
errorf: true
45+
asserts: true
46+
comparison: true
47+
forbidigo:
48+
forbid:
49+
- pattern: fmt.Print.* # too much log noise
50+
exclude-godoc-examples: true
51+
gomoddirectives:
52+
replace-local: false
53+
gomodguard:
54+
blocked:
55+
modules:
56+
- github.com/pkg/errors:
57+
recommendations:
58+
- errors
59+
- fmt
60+
reason: This package is deprecated, use fmt.Errorf with %%w instead
61+
- github.com/elastic/beats/v7:
62+
reason: There must be no Beats dependency
63+
gosec:
64+
excludes:
65+
- G306 # Expect WriteFile permissions to be 0600 or less
66+
- G404 # Use of weak random number generator
67+
- G401 # Detect the usage of DES, RC4, MD5 or SHA1: Used in non-crypto contexts.
68+
- G501 # Import blocklist: crypto/md5: Used in non-crypto contexts.
69+
- G505 # Import blocklist: crypto/sha1: Used in non-crypto contexts.
70+
nolintlint:
71+
require-explanation: true
72+
require-specific: true
73+
allow-unused: false
74+
staticcheck:
75+
checks:
76+
- all
77+
exclusions:
78+
generated: lax
79+
presets:
80+
- comments
81+
- common-false-positives
82+
- legacy
83+
- std-error-handling
84+
paths:
85+
- third_party$
86+
- builtin$
87+
- examples$
88+
issues:
89+
max-issues-per-linter: 0
90+
max-same-issues: 0
12091

121-
gosec:
122-
excludes:
123-
- G306 # Expect WriteFile permissions to be 0600 or less
124-
- G404 # Use of weak random number generator
125-
- G401 # Detect the usage of DES, RC4, MD5 or SHA1: Used in non-crypto contexts.
126-
- G501 # Import blocklist: crypto/md5: Used in non-crypto contexts.
127-
- G505 # Import blocklist: crypto/sha1: Used in non-crypto contexts.
92+
formatters:
93+
enable:
94+
- goimports
95+
exclusions:
96+
generated: lax
97+
paths:
98+
- third_party$
99+
- builtin$
100+
- examples$

dev-tools/mage/linter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
const (
34-
linterVersion = "v1.64.8"
34+
linterVersion = "v2.0.2"
3535
linterInstallURL = "https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
3636
)
3737

0 commit comments

Comments
 (0)