Skip to content

Commit fd33b81

Browse files
authored
Fix linting (#2903)
1 parent 66b1147 commit fd33b81

File tree

95 files changed

+323
-333
lines changed

Some content is hidden

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

95 files changed

+323
-333
lines changed

.github/workflows/linter.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ jobs:
99
lint:
1010
strategy:
1111
matrix:
12-
go-version: [1.x]
1312
platform: [ubuntu-latest]
1413

1514
# golangci-lint will only process a single module, so we need to call it
1615
# separately for each module in the repo. We dont lint example/newreposecretwithlibsodium
1716
# since that needs libsodium to run.
1817
working-directory:
1918
- ""
20-
# - example # Fails with "no go files to analyze"
19+
- example
2120
- scrape
2221
- update-urls
2322
runs-on: ${{ matrix.platform }}

.golangci.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1+
run:
2+
build-tags:
3+
- integration
14
linters:
2-
# TODO: fix errors so that all of the linters below pass.
3-
# The linters that are commented out, as well as those explicitly disabled,
4-
# are currently failing. We should fix those failures or define exclusion
5-
# rules, and then enable those linters.
65
enable:
76
- dogsled
87
- dupl
98
- gofmt
109
- goimports
11-
# - gosec
10+
- gosec
1211
- misspell
1312
- nakedret
1413
- stylecheck
15-
# - unconvert
16-
# - unparam
14+
- unconvert
15+
- unparam
1716
- whitespace
18-
disable:
19-
- errcheck
20-
- gosimple
21-
- staticcheck
22-
- ineffassign
23-
- unused
17+
linters-settings:
18+
gosec:
19+
excludes:
20+
# performance issue: see https://github.com/golangci/golangci-lint/issues/4039
21+
# and https://github.com/securego/gosec/issues/1007
22+
- G602
2423
issues:
25-
exclude:
26-
- composites
2724
exclude-rules:
28-
- linters:
29-
- dogsled
30-
text: "declaration has 3 blank identifiers"
31-
path: _test\.go
32-
- linters:
33-
- dupl
34-
path: _test\.go
25+
- linters:
26+
- dupl
27+
- unparam
28+
- gosec
29+
- dogsled
30+
path: _test\.go
31+
32+
# We need to pass nil Context in order to test DoBare erroring on nil ctx.
33+
- linters: [ staticcheck ]
34+
text: 'SA1012: do not pass a nil Context'
35+
path: _test\.go
36+
37+
# We need to use sha1 for validating signatures
38+
- linters: [ gosec ]
39+
text: 'G505: Blocklisted import crypto/sha1: weak cryptographic primitive'

example/basicauth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func main() {
3232
username, _ := r.ReadString('\n')
3333

3434
fmt.Print("GitHub Password: ")
35-
bytePassword, _ := term.ReadPassword(int(syscall.Stdin))
35+
bytePassword, _ := term.ReadPassword(syscall.Stdin)
3636
password := string(bytePassword)
3737

3838
tp := github.BasicAuthTransport{

example/commitpr/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func pushCommit(ref *github.Reference, tree *github.Tree) (err error) {
133133

134134
// Create the commit using the tree.
135135
date := time.Now()
136-
author := &github.CommitAuthor{Date: &github.Timestamp{date}, Name: authorName, Email: authorEmail}
136+
author := &github.CommitAuthor{Date: &github.Timestamp{Time: date}, Name: authorName, Email: authorEmail}
137137
commit := &github.Commit{Author: author, Message: commitMessage, Tree: tree, Parents: []*github.Commit{parent.Commit}}
138138
newCommit, _, err := client.Git.CreateCommit(ctx, *sourceOwner, *sourceRepo, commit)
139139
if err != nil {

example/tagprotection/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func main() {
3939
pattern = strings.TrimSpace(pattern)
4040

4141
fmt.Print("GitHub Token: ")
42-
byteToken, _ := term.ReadPassword(int(syscall.Stdin))
42+
byteToken, _ := term.ReadPassword(syscall.Stdin)
4343
println()
4444
token := string(byteToken)
4545

example/tokenauth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
func main() {
2323
fmt.Print("GitHub Token: ")
24-
byteToken, _ := term.ReadPassword(int(syscall.Stdin))
24+
byteToken, _ := term.ReadPassword(syscall.Stdin)
2525
println()
2626
token := string(byteToken)
2727

github/actions_runners_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestActionsService_GenerateOrgJITConfig(t *testing.T) {
6565

6666
mux.HandleFunc("/orgs/o/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
6767
v := new(GenerateJITConfigRequest)
68-
json.NewDecoder(r.Body).Decode(v)
68+
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
6969

7070
testMethod(t, r, "POST")
7171
if !cmp.Equal(v, input) {
@@ -109,7 +109,7 @@ func TestActionsService_GenerateRepoJITConfig(t *testing.T) {
109109

110110
mux.HandleFunc("/repos/o/r/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
111111
v := new(GenerateJITConfigRequest)
112-
json.NewDecoder(r.Body).Decode(v)
112+
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
113113

114114
testMethod(t, r, "POST")
115115
if !cmp.Equal(v, input) {

github/actions_secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type PublicKey struct {
2323
// do not error out when unmarshaling.
2424
func (p *PublicKey) UnmarshalJSON(data []byte) error {
2525
var pk struct {
26-
KeyID interface{} `json:"key_id,string"`
26+
KeyID interface{} `json:"key_id"`
2727
Key *string `json:"key"`
2828
}
2929

github/actions_workflow_runs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ func TestActionService_PendingDeployments(t *testing.T) {
12471247

12481248
mux.HandleFunc("/repos/o/r/actions/runs/399444496/pending_deployments", func(w http.ResponseWriter, r *http.Request) {
12491249
v := new(PendingDeploymentsRequest)
1250-
json.NewDecoder(r.Body).Decode(v)
1250+
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
12511251

12521252
testMethod(t, r, "POST")
12531253
if !cmp.Equal(v, input) {

github/actions_workflows_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {
243243
}
244244
mux.HandleFunc("/repos/o/r/actions/workflows/72844/dispatches", func(w http.ResponseWriter, r *http.Request) {
245245
var v CreateWorkflowDispatchEventRequest
246-
json.NewDecoder(r.Body).Decode(&v)
246+
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))
247247

248248
testMethod(t, r, "POST")
249249
if !cmp.Equal(v, event) {
@@ -287,7 +287,7 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) {
287287
}
288288
mux.HandleFunc("/repos/o/r/actions/workflows/main.yml/dispatches", func(w http.ResponseWriter, r *http.Request) {
289289
var v CreateWorkflowDispatchEventRequest
290-
json.NewDecoder(r.Body).Decode(&v)
290+
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))
291291

292292
testMethod(t, r, "POST")
293293
if !cmp.Equal(v, event) {

0 commit comments

Comments
 (0)