Skip to content

Commit e1db5e6

Browse files
authored
chore: Migrate golangci-lint to v2 (#3587)
1 parent 3c5408e commit e1db5e6

File tree

4 files changed

+130
-130
lines changed

4 files changed

+130
-130
lines changed

.custom-gcl.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: v1.62.0
1+
version: v2.1.6
22
plugins:
33
- module: "github.com/google/go-github/v68/tools/sliceofpointers"
44
path: ./tools/sliceofpointers

.golangci.yml

Lines changed: 121 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,152 @@
1+
version: "2"
12
run:
23
build-tags:
34
- integration
4-
timeout: 10m
55
linters:
66
enable:
77
- canonicalheader
88
- copyloopvar
99
- dogsled
1010
- dupl
11-
- gci
1211
- gocritic
1312
- godot
14-
- gofmt
1513
- goheader
16-
- goimports
1714
- gosec
1815
- misspell
1916
- nakedret
2017
- paralleltest
2118
- perfsprint
2219
- revive
2320
- sliceofpointers
24-
- stylecheck
21+
- staticcheck
2522
- tparallel
2623
- unconvert
2724
- unparam
2825
- whitespace
29-
linters-settings:
30-
custom:
31-
sliceofpointers:
32-
type: module
33-
description: Reports usage of []*string and slices of structs without pointers.
34-
original-url: github.com/google/go-github/v68/tools/sliceofpointers
35-
gocritic:
36-
disable-all: true
37-
enabled-checks:
38-
- commentedOutCode
39-
- commentFormatting
40-
goheader:
41-
values:
42-
regexp:
43-
CopyrightDate: "Copyright \\d{4} "
44-
template: |-
45-
{{CopyrightDate}}The go-github AUTHORS. All rights reserved.
26+
settings:
27+
gocritic:
28+
disable-all: true
29+
enabled-checks:
30+
- commentedOutCode
31+
- commentFormatting
32+
goheader:
33+
values:
34+
regexp:
35+
CopyrightDate: 'Copyright \d{4} '
36+
template: |-
37+
{{CopyrightDate}}The go-github AUTHORS. All rights reserved.
4638
47-
Use of this source code is governed by a BSD-style
48-
license that can be found in the LICENSE file.
49-
gosec:
50-
excludes:
51-
# duplicates errcheck
52-
- G104
53-
# int(os.Stdin.Fd())
54-
- G115
55-
misspell:
56-
locale: US
57-
ignore-words:
58-
- "analyses" # returned by the GitHub API
59-
- "cancelled" # returned by the GitHub API
60-
# extra words from https://go.dev//wiki/Spelling
61-
extra-words:
62-
- typo: "marshall"
63-
correction: "marshal"
64-
- typo: "marshalled"
65-
correction: "marshaled"
66-
- typo: "marshalling"
67-
correction: "marshaling"
68-
- typo: "unmarshall"
69-
correction: "unmarshal"
70-
- typo: "unmarshalling"
71-
correction: "unmarshaling"
72-
- typo: "unmarshalled"
73-
correction: "unmarshaled"
74-
- typo: "unmarshalling"
75-
correction: "unmarshaling"
76-
perfsprint:
77-
errorf: true
78-
strconcat: false
79-
revive:
80-
# Set below 0.8 to enable error-strings rule.
81-
confidence: 0.6
39+
Use of this source code is governed by a BSD-style
40+
license that can be found in the LICENSE file.
41+
gosec:
42+
excludes:
43+
# duplicates errcheck
44+
- G104
45+
# int(os.Stdin.Fd())
46+
- G115
47+
misspell:
48+
locale: US
49+
# extra words from https://go.dev//wiki/Spelling
50+
extra-words:
51+
- typo: marshall
52+
correction: marshal
53+
- typo: marshalled
54+
correction: marshaled
55+
- typo: marshalling
56+
correction: marshaling
57+
- typo: unmarshall
58+
correction: unmarshal
59+
- typo: unmarshalling
60+
correction: unmarshaling
61+
- typo: unmarshalled
62+
correction: unmarshaled
63+
- typo: unmarshalling
64+
correction: unmarshaling
65+
ignore-rules:
66+
- analyses # returned by the GitHub API
67+
- cancelled # returned by the GitHub API
68+
perfsprint:
69+
errorf: true
70+
strconcat: false
71+
revive:
72+
# Set below 0.8 to enable error-strings rule.
73+
confidence: 0.6
74+
rules:
75+
- name: blank-imports
76+
- name: bool-literal-in-expr
77+
- name: context-as-argument
78+
- name: context-keys-type
79+
- name: dot-imports
80+
- name: early-return
81+
- name: empty-block
82+
- name: error-naming
83+
- name: error-return
84+
- name: error-strings
85+
- name: errorf
86+
- name: filename-format
87+
arguments:
88+
- ^[_a-z][_a-z0-9]*.go$
89+
- name: increment-decrement
90+
- name: indent-error-flow
91+
- name: package-comments
92+
- name: range
93+
- name: receiver-naming
94+
- name: redefines-builtin-id
95+
- name: superfluous-else
96+
- name: time-equal
97+
- name: time-naming
98+
- name: unexported-naming
99+
- name: unexported-return
100+
- name: unreachable-code
101+
- name: use-any
102+
- name: var-declaration
103+
- name: var-naming
104+
staticcheck:
105+
checks:
106+
- "all"
107+
- "-QF1008" # allow embedded field in selector
108+
custom:
109+
sliceofpointers:
110+
type: module
111+
description: Reports usage of []*string and slices of structs without pointers.
112+
original-url: github.com/google/go-github/v68/tools/sliceofpointers
113+
exclusions:
82114
rules:
83-
- name: blank-imports
84-
- name: bool-literal-in-expr
85-
- name: context-as-argument
86-
- name: context-keys-type
87-
- name: dot-imports
88-
- name: early-return
89-
- name: empty-block
90-
- name: error-naming
91-
- name: error-return
92-
- name: error-strings
93-
- name: errorf
94-
- name: filename-format
95-
arguments:
96-
- "^[_a-z][_a-z0-9]*.go$"
97-
- name: increment-decrement
98-
- name: indent-error-flow
99-
- name: package-comments
100-
- name: range
101-
- name: receiver-naming
102-
- name: redefines-builtin-id
103-
- name: superfluous-else
104-
- name: time-equal
105-
- name: time-naming
106-
- name: unexported-naming
107-
- name: unexported-return
108-
- name: unreachable-code
109-
- name: use-any
110-
- name: var-declaration
111-
- name: var-naming
112-
issues:
113-
exclude-use-default: false
114-
exclude-rules:
115-
- linters:
116-
- dupl
117-
- unparam
118-
- gosec
119-
- dogsled
120-
path: _test\.go
115+
- linters:
116+
- dogsled
117+
- dupl
118+
- gosec
119+
- unparam
120+
path: _test\.go
121121

122-
# We need to pass nil Context in order to test DoBare erroring on nil ctx.
123-
- linters: [staticcheck]
124-
text: "SA1012: do not pass a nil Context"
125-
path: _test\.go
122+
# We need to pass nil Context in order to test DoBare erroring on nil ctx.
123+
- linters: [staticcheck]
124+
path: _test\.go
125+
text: 'SA1012: do not pass a nil Context'
126126

127-
# We need to use sha1 for validating signatures
128-
- linters: [gosec]
129-
text: "G505: Blocklisted import crypto/sha1: weak cryptographic primitive"
127+
# We need to use sha1 for validating signatures
128+
- linters: [gosec]
129+
text: 'G505: Blocklisted import crypto/sha1: weak cryptographic primitive'
130130

131-
# This is adapted from golangci-lint's default exclusions. It disables linting for error checks on
132-
# os.RemoveAll, fmt.Fprint*, fmt.Scanf, and any function ending in "Close".
133-
- linters: [errcheck]
134-
text: Error return value of .(.*Close|fmt\.Fprint.*|fmt\.Scanf|os\.Remove(All)?). is not checked
131+
# This is adapted from golangci-lint's default exclusions. It disables linting for error checks on
132+
# os.RemoveAll, fmt.Fprint*, fmt.Scanf, and any function ending in "Close".
133+
- linters: [errcheck]
134+
text: Error return value of .(.*Close|fmt\.Fprint.*|fmt\.Scanf|os\.Remove(All)?). is not checked
135135

136-
# We don't care about file inclusion via variable in examples or internal tools.
137-
- linters: [gosec]
138-
text: "G304: Potential file inclusion via variable"
139-
path: '^(example|tools)\/'
136+
# We don't care about file inclusion via variable in examples or internal tools.
137+
- linters: [gosec]
138+
path: ^(example|tools)\/
139+
text: 'G304: Potential file inclusion via variable'
140140

141-
# We don't run parallel integration tests
142-
- linters: [paralleltest, tparallel]
143-
path: "^test/integration"
141+
# We don't run parallel integration tests
142+
- linters: [paralleltest, tparallel]
143+
path: ^test/integration
144144

145-
# Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10).
146-
- linters: [perfsprint]
147-
text: "fmt.Sprint.* can be replaced with faster strconv.FormatInt"
145+
# Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10).
146+
- linters: [perfsprint]
147+
text: fmt.Sprint.* can be replaced with faster strconv.FormatInt
148+
formatters:
149+
enable:
150+
- gci
151+
- gofmt
152+
- goimports

github/search.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,20 @@ func (s *SearchService) search(ctx context.Context, searchType string, parameter
317317
return nil, err
318318
}
319319
var acceptHeaders []string
320-
switch {
321-
case searchType == "commits":
320+
switch searchType {
321+
case "commits":
322322
// Accept header for search commits preview endpoint
323323
// TODO: remove custom Accept header when this API fully launches.
324324
acceptHeaders = append(acceptHeaders, mediaTypeCommitSearchPreview)
325-
case searchType == "topics":
325+
case "topics":
326326
// Accept header for search repositories based on topics preview endpoint
327327
// TODO: remove custom Accept header when this API fully launches.
328328
acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview)
329-
case searchType == "repositories":
329+
case "repositories":
330330
// Accept header for search repositories based on topics preview endpoint
331331
// TODO: remove custom Accept header when this API fully launches.
332332
acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview)
333-
case searchType == "issues":
333+
case "issues":
334334
// Accept header for search issues based on reactions preview endpoint
335335
// TODO: remove custom Accept header when this API fully launches.
336336
acceptHeaders = append(acceptHeaders, mediaTypeReactionsPreview)

script/lint.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
set -e
77

8-
GOLANGCI_LINT_VERSION="1.63.4"
8+
GOLANGCI_LINT_VERSION="2.1.6"
99

1010
CDPATH="" cd -- "$(dirname -- "$0")/.."
1111
BIN="$(pwd -P)"/bin
@@ -21,7 +21,7 @@ fail() {
2121

2222
# install golangci-lint and custom-gcl in ./bin if they don't exist with the correct version
2323
if ! "$BIN"/custom-gcl --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then
24-
GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION"
24+
GOBIN="$BIN" go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION"
2525
"$BIN"/golangci-lint custom && mv ./custom-gcl "$BIN"
2626
fi
2727

@@ -32,12 +32,7 @@ for dir in $MOD_DIRS; do
3232
echo linting "$dir"
3333
(
3434
cd "$dir"
35-
# github actions output when running in an action
36-
if [ -n "$GITHUB_ACTIONS" ]; then
37-
"$BIN"/custom-gcl run --path-prefix "$dir" --out-format colored-line-number
38-
else
39-
"$BIN"/custom-gcl run --path-prefix "$dir"
40-
fi
35+
"$BIN"/custom-gcl run --path-prefix "$dir"
4136
) || fail "failed linting $dir"
4237
done
4338

0 commit comments

Comments
 (0)