diff --git a/.golangci.yml b/.golangci.yml index 2bfeaaa24dc..d97416041cd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: - gosec - misspell - nakedret + - perfsprint - paralleltest - stylecheck - tparallel @@ -24,6 +25,9 @@ linters-settings: - G104 # int(os.Stdin.Fd()) - G115 + perfsprint: + errorf: true + strconcat: false issues: exclude-use-default: false exclude-rules: @@ -56,3 +60,7 @@ issues: # We don't run parallel integration tests - linters: [ paralleltest, tparallel ] path: '^test/integration' + + # Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10). + - linters: [ perfsprint] + text: 'fmt.Sprint.* can be replaced with faster strconv.FormatInt' diff --git a/example/codespaces/newreposecretwithxcrypto/main.go b/example/codespaces/newreposecretwithxcrypto/main.go index bd6033ec5af..df7cd97fb36 100644 --- a/example/codespaces/newreposecretwithxcrypto/main.go +++ b/example/codespaces/newreposecretwithxcrypto/main.go @@ -31,6 +31,7 @@ import ( "context" crypto_rand "crypto/rand" "encoding/base64" + "errors" "flag" "fmt" "log" @@ -84,7 +85,7 @@ func main() { func getSecretName() (string, error) { secretName := flag.Arg(0) if secretName == "" { - return "", fmt.Errorf("missing argument secret name") + return "", errors.New("missing argument secret name") } return secretName, nil } diff --git a/example/codespaces/newusersecretwithxcrypto/main.go b/example/codespaces/newusersecretwithxcrypto/main.go index e1fec87de33..e306ae3de79 100644 --- a/example/codespaces/newusersecretwithxcrypto/main.go +++ b/example/codespaces/newusersecretwithxcrypto/main.go @@ -32,6 +32,7 @@ import ( "context" crypto_rand "crypto/rand" "encoding/base64" + "errors" "flag" "fmt" "log" @@ -77,7 +78,7 @@ func main() { func getSecretName() (string, error) { secretName := flag.Arg(0) if secretName == "" { - return "", fmt.Errorf("missing argument secret name") + return "", errors.New("missing argument secret name") } return secretName, nil } diff --git a/example/newreposecretwithxcrypto/main.go b/example/newreposecretwithxcrypto/main.go index 6737263aa08..9c1a42b04eb 100644 --- a/example/newreposecretwithxcrypto/main.go +++ b/example/newreposecretwithxcrypto/main.go @@ -31,6 +31,7 @@ import ( "context" crypto_rand "crypto/rand" "encoding/base64" + "errors" "flag" "fmt" "log" @@ -84,7 +85,7 @@ func main() { func getSecretName() (string, error) { secretName := flag.Arg(0) if secretName == "" { - return "", fmt.Errorf("missing argument secret name") + return "", errors.New("missing argument secret name") } return secretName, nil } diff --git a/github/copilot.go b/github/copilot.go index 2697b71850c..349b16ebde6 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -8,6 +8,7 @@ package github import ( "context" "encoding/json" + "errors" "fmt" ) @@ -87,7 +88,7 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { } if v["type"] == nil { - return fmt.Errorf("assignee type field is not set") + return errors.New("assignee type field is not set") } if t, ok := v["type"].(string); ok && t == "User" { diff --git a/github/git_commits.go b/github/git_commits.go index 573d38be528..fdb3d26ceab 100644 --- a/github/git_commits.go +++ b/github/git_commits.go @@ -129,7 +129,7 @@ type CreateCommitOptions struct { //meta:operation POST /repos/{owner}/{repo}/git/commits func (s *GitService) CreateCommit(ctx context.Context, owner string, repo string, commit *Commit, opts *CreateCommitOptions) (*Commit, *Response, error) { if commit == nil { - return nil, nil, fmt.Errorf("commit must be provided") + return nil, nil, errors.New("commit must be provided") } if opts == nil { opts = &CreateCommitOptions{} diff --git a/github/git_commits_test.go b/github/git_commits_test.go index d99787fab1c..9ea876050e6 100644 --- a/github/git_commits_test.go +++ b/github/git_commits_test.go @@ -8,6 +8,7 @@ package github import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -402,7 +403,7 @@ func TestGitService_createSignature_signerError(t *testing.T) { Author: &CommitAuthor{Name: String("go-github")}, } - signer := mockSigner(t, "", fmt.Errorf("signer error"), "") + signer := mockSigner(t, "", errors.New("signer error"), "") _, err := createSignature(signer, a) if err == nil { diff --git a/github/orgs_properties.go b/github/orgs_properties.go index 3387d98d76f..d8db48fc94e 100644 --- a/github/orgs_properties.go +++ b/github/orgs_properties.go @@ -8,6 +8,7 @@ package github import ( "context" "encoding/json" + "errors" "fmt" ) @@ -69,7 +70,7 @@ func (cpv *CustomPropertyValue) UnmarshalJSON(data []byte) error { if str, ok := item.(string); ok { strSlice[i] = str } else { - return fmt.Errorf("non-string value in string array") + return errors.New("non-string value in string array") } } cpv.Value = strSlice diff --git a/github/pulls.go b/github/pulls.go index b668502691e..35ceda44679 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -8,6 +8,7 @@ package github import ( "bytes" "context" + "errors" "fmt" ) @@ -352,7 +353,7 @@ type pullRequestUpdate struct { //meta:operation PATCH /repos/{owner}/{repo}/pulls/{pull_number} func (s *PullRequestsService) Edit(ctx context.Context, owner string, repo string, number int, pull *PullRequest) (*PullRequest, *Response, error) { if pull == nil { - return nil, nil, fmt.Errorf("pull must be provided") + return nil, nil, errors.New("pull must be provided") } u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number) diff --git a/tools/metadata/main.go b/tools/metadata/main.go index 238fc468856..7be3cbed656 100644 --- a/tools/metadata/main.go +++ b/tools/metadata/main.go @@ -10,6 +10,7 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -70,7 +71,7 @@ func (c *rootCmd) opsFile() (string, *operationsFile, error) { func githubClient(apiURL string) (*github.Client, error) { token := os.Getenv("GITHUB_TOKEN") if token == "" { - return nil, fmt.Errorf("GITHUB_TOKEN environment variable must be set to a GitHub personal access token with the public_repo scope") + return nil, errors.New("GITHUB_TOKEN environment variable must be set to a GitHub personal access token with the public_repo scope") } return github.NewClient(nil).WithAuthToken(token).WithEnterpriseURLs(apiURL, "") } @@ -83,7 +84,7 @@ type updateOpenAPICmd struct { func (c *updateOpenAPICmd) Run(root *rootCmd) error { ctx := context.Background() if c.ValidateGithub && c.Ref != "main" { - return fmt.Errorf("--validate and --ref are mutually exclusive") + return errors.New("--validate and --ref are mutually exclusive") } filename, opsFile, err := root.opsFile() if err != nil { @@ -102,7 +103,7 @@ func (c *updateOpenAPICmd) Run(root *rootCmd) error { if c.ValidateGithub { ref = opsFile.GitCommit if ref == "" { - return fmt.Errorf("openapi_operations.yaml does not have an openapi_commit field") + return errors.New("openapi_operations.yaml does not have an openapi_commit field") } } err = opsFile.updateFromGithub(ctx, client, ref) @@ -113,7 +114,7 @@ func (c *updateOpenAPICmd) Run(root *rootCmd) error { return opsFile.saveFile(filename) } if !operationsEqual(origOps, opsFile.OpenapiOps) { - return fmt.Errorf("openapi_operations.yaml does not match the OpenAPI descriptions in github.com/github/rest-api-description") + return errors.New("openapi_operations.yaml does not match the OpenAPI descriptions in github.com/github/rest-api-description") } return nil }