Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting #2903

Merged
merged 5 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ jobs:
lint:
strategy:
matrix:
go-version: [1.x]
platform: [ubuntu-latest]

# golangci-lint will only process a single module, so we need to call it
# separately for each module in the repo. We dont lint example/newreposecretwithlibsodium
# since that needs libsodium to run.
working-directory:
- ""
# - example # Fails with "no go files to analyze"
- example
- scrape
- update-urls
runs-on: ${{ matrix.platform }}
Expand Down
49 changes: 27 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
run:
build-tags:
- integration
linters:
# TODO: fix errors so that all of the linters below pass.
# The linters that are commented out, as well as those explicitly disabled,
# are currently failing. We should fix those failures or define exclusion
# rules, and then enable those linters.
enable:
- dogsled
- dupl
- gofmt
- goimports
# - gosec
- gosec
- misspell
- nakedret
- stylecheck
# - unconvert
# - unparam
- unconvert
- unparam
- whitespace
disable:
- errcheck
- gosimple
- staticcheck
- ineffassign
- unused
linters-settings:
gosec:
excludes:
# performance issue: see https://github.com/golangci/golangci-lint/issues/4039
# and https://github.com/securego/gosec/issues/1007
- G602
issues:
exclude:
- composites
exclude-rules:
- linters:
- dogsled
text: "declaration has 3 blank identifiers"
path: _test\.go
- linters:
- dupl
path: _test\.go
- linters:
- dupl
- unparam
- gosec
- dogsled
path: _test\.go

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

# We need to use sha1 for validating signatures
- linters: [ gosec ]
text: 'G505: Blocklisted import crypto/sha1: weak cryptographic primitive'
2 changes: 1 addition & 1 deletion example/basicauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
username, _ := r.ReadString('\n')

fmt.Print("GitHub Password: ")
bytePassword, _ := term.ReadPassword(int(syscall.Stdin))
bytePassword, _ := term.ReadPassword(syscall.Stdin)
password := string(bytePassword)

tp := github.BasicAuthTransport{
Expand Down
2 changes: 1 addition & 1 deletion example/commitpr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func pushCommit(ref *github.Reference, tree *github.Tree) (err error) {

// Create the commit using the tree.
date := time.Now()
author := &github.CommitAuthor{Date: &github.Timestamp{date}, Name: authorName, Email: authorEmail}
author := &github.CommitAuthor{Date: &github.Timestamp{Time: date}, Name: authorName, Email: authorEmail}
commit := &github.Commit{Author: author, Message: commitMessage, Tree: tree, Parents: []*github.Commit{parent.Commit}}
newCommit, _, err := client.Git.CreateCommit(ctx, *sourceOwner, *sourceRepo, commit)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion example/tagprotection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
pattern = strings.TrimSpace(pattern)

fmt.Print("GitHub Token: ")
byteToken, _ := term.ReadPassword(int(syscall.Stdin))
byteToken, _ := term.ReadPassword(syscall.Stdin)
println()
token := string(byteToken)

Expand Down
2 changes: 1 addition & 1 deletion example/tokenauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func main() {
fmt.Print("GitHub Token: ")
byteToken, _ := term.ReadPassword(int(syscall.Stdin))
byteToken, _ := term.ReadPassword(syscall.Stdin)
println()
token := string(byteToken)

Expand Down
4 changes: 2 additions & 2 deletions github/actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestActionsService_GenerateOrgJITConfig(t *testing.T) {

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

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

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

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
Expand Down
2 changes: 1 addition & 1 deletion github/actions_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type PublicKey struct {
// do not error out when unmarshaling.
func (p *PublicKey) UnmarshalJSON(data []byte) error {
var pk struct {
KeyID interface{} `json:"key_id,string"`
KeyID interface{} `json:"key_id"`
Key *string `json:"key"`
}

Expand Down
2 changes: 1 addition & 1 deletion github/actions_workflow_runs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ func TestActionService_PendingDeployments(t *testing.T) {

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

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
Expand Down
4 changes: 2 additions & 2 deletions github/actions_workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {
}
mux.HandleFunc("/repos/o/r/actions/workflows/72844/dispatches", func(w http.ResponseWriter, r *http.Request) {
var v CreateWorkflowDispatchEventRequest
json.NewDecoder(r.Body).Decode(&v)
assertNilError(t, json.NewDecoder(r.Body).Decode(&v))

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

testMethod(t, r, "POST")
if !cmp.Equal(v, event) {
Expand Down
2 changes: 1 addition & 1 deletion github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestActivityService_SetThreadSubscription(t *testing.T) {

mux.HandleFunc("/notifications/threads/1/subscription", func(w http.ResponseWriter, r *http.Request) {
v := new(Subscription)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
Expand Down
2 changes: 1 addition & 1 deletion github/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestActivityService_List(t *testing.T) {
testMethod(t, r, "GET")

w.WriteHeader(http.StatusOK)
w.Write(feedsJSON)
assertWrite(t, w, feedsJSON)
})

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion github/activity_watching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestActivityService_SetRepositorySubscription(t *testing.T) {

mux.HandleFunc("/repos/o/r/subscription", func(w http.ResponseWriter, r *http.Request) {
v := new(Subscription)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PUT")
if !cmp.Equal(v, input) {
Expand Down
6 changes: 3 additions & 3 deletions github/admin_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAdminOrgs_Create(t *testing.T) {

mux.HandleFunc("/admin/organizations", func(w http.ResponseWriter, r *http.Request) {
v := new(createOrgRequest)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")
want := &createOrgRequest{Login: String("github"), Admin: String("ghAdmin")}
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestAdminOrgs_Rename(t *testing.T) {

mux.HandleFunc("/admin/organizations/o", func(w http.ResponseWriter, r *http.Request) {
v := new(renameOrgRequest)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
want := &renameOrgRequest{Login: String("the-new-octocats")}
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestAdminOrgs_RenameByName(t *testing.T) {

mux.HandleFunc("/admin/organizations/o", func(w http.ResponseWriter, r *http.Request) {
v := new(renameOrgRequest)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
want := &renameOrgRequest{Login: String("the-new-octocats")}
Expand Down
4 changes: 2 additions & 2 deletions github/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAdminService_UpdateUserLDAPMapping(t *testing.T) {

mux.HandleFunc("/admin/ldap/users/u/mapping", func(w http.ResponseWriter, r *http.Request) {
v := new(UserLDAPMapping)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
if !cmp.Equal(v, input) {
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) {

mux.HandleFunc("/admin/ldap/teams/1/mapping", func(w http.ResponseWriter, r *http.Request) {
v := new(TeamLDAPMapping)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
if !cmp.Equal(v, input) {
Expand Down
2 changes: 1 addition & 1 deletion github/admin_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAdminUsers_Create(t *testing.T) {

mux.HandleFunc("/admin/users", func(w http.ResponseWriter, r *http.Request) {
v := new(createUserRequest)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")
want := &createUserRequest{Login: String("github"), Email: String("[email protected]")}
Expand Down
4 changes: 2 additions & 2 deletions github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func TestAppsService_CreateInstallationTokenWithOptions(t *testing.T) {

mux.HandleFunc("/app/installations/1/access_tokens", func(w http.ResponseWriter, r *http.Request) {
v := new(InstallationTokenOptions)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

if !cmp.Equal(v, installationTokenOptions) {
t.Errorf("request sent %+v, want %+v", v, installationTokenOptions)
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestAppsService_CreateAttachement(t *testing.T) {
testHeader(t, r, "Accept", mediaTypeContentAttachmentsPreview)

w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"id":1,"title":"title1","body":"body1"}`))
assertWrite(t, w, []byte(`{"id":1,"title":"title1","body":"body1"}`))
})

ctx := context.Background()
Expand Down
6 changes: 3 additions & 3 deletions github/code-scanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestCodeScanningService_UploadSarif(t *testing.T) {

mux.HandleFunc("/repos/o/r/code-scanning/sarifs", func(w http.ResponseWriter, r *http.Request) {
v := new(SarifAnalysis)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
testMethod(t, r, "POST")
want := &SarifAnalysis{CommitSHA: String("abc"), Ref: String("ref/head/main"), Sarif: String("abc"), CheckoutURI: String("uri"), StartedAt: &Timestamp{time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC)}, ToolName: String("codeql-cli")}
if !cmp.Equal(v, want) {
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestCodeScanningService_ListAlertsForOrg(t *testing.T) {
},
}
if !cmp.Equal(alerts, want) {
t.Errorf("CodeScanning.ListAlertsForOrg returned %+v, want %+v", *&alerts, *&want)
t.Errorf("CodeScanning.ListAlertsForOrg returned %+v, want %+v", alerts, want)
}

const methodName = "ListAlertsForOrg"
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestCodeScanningService_ListAlertsForOrgLisCursorOptions(t *testing.T) {
},
}
if !cmp.Equal(alerts, want) {
t.Errorf("CodeScanning.ListAlertsForOrg returned %+v, want %+v", *&alerts, *&want)
t.Errorf("CodeScanning.ListAlertsForOrg returned %+v, want %+v", alerts, want)
}

const methodName = "ListAlertsForOrg"
Expand Down
5 changes: 4 additions & 1 deletion github/enterprise_actions_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ func TestEnterpriseService_GenerateEnterpriseJITConfig(t *testing.T) {

mux.HandleFunc("/enterprises/o/actions/runners/generate-jitconfig", func(w http.ResponseWriter, r *http.Request) {
v := new(GenerateJITConfigRequest)
json.NewDecoder(r.Body).Decode(v)
err := json.NewDecoder(r.Body).Decode(v)
if err != nil {
t.Errorf("Request body decode failed: %v", err)
}

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
Expand Down
2 changes: 1 addition & 1 deletion github/enterprise_code_security_and_analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestEnterpriseService_UpdateCodeSecurityAndAnalysis(t *testing.T) {

mux.HandleFunc("/enterprises/e/code_security_and_analysis", func(w http.ResponseWriter, r *http.Request) {
v := new(EnterpriseSecurityAnalysisSettings)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
if !cmp.Equal(v, input) {
Expand Down
4 changes: 2 additions & 2 deletions github/gists_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestGistsService_CreateComment(t *testing.T) {

mux.HandleFunc("/gists/1/comments", func(w http.ResponseWriter, r *http.Request) {
v := new(GistComment)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestGistsService_EditComment(t *testing.T) {

mux.HandleFunc("/gists/1/comments/2", func(w http.ResponseWriter, r *http.Request) {
v := new(GistComment)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
if !cmp.Equal(v, input) {
Expand Down
4 changes: 2 additions & 2 deletions github/gists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func TestGistsService_Create(t *testing.T) {

mux.HandleFunc("/gists", func(w http.ResponseWriter, r *http.Request) {
v := new(Gist)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestGistsService_Edit(t *testing.T) {

mux.HandleFunc("/gists/1", func(w http.ResponseWriter, r *http.Request) {
v := new(Gist)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "PATCH")
if !cmp.Equal(v, input) {
Expand Down
2 changes: 1 addition & 1 deletion github/git_blobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGitService_CreateBlob(t *testing.T) {

mux.HandleFunc("/repos/o/r/git/blobs", func(w http.ResponseWriter, r *http.Request) {
v := new(Blob)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")

Expand Down
6 changes: 3 additions & 3 deletions github/git_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestGitService_CreateCommit(t *testing.T) {

mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) {
v := new(createCommit)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")

Expand Down Expand Up @@ -232,7 +232,7 @@ func TestGitService_CreateSignedCommit(t *testing.T) {

mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) {
v := new(createCommit)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")

Expand Down Expand Up @@ -335,7 +335,7 @@ Commit Message.`)

mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) {
v := new(createCommit)
json.NewDecoder(r.Body).Decode(v)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))

testMethod(t, r, "POST")

Expand Down
Loading
Loading