8000 refactor: Enable perfsprint; fix appeared lint issues by alexandear · Pull Request #3324 · google/go-github · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: Enable perfsprint; fix appeared lint issues #3324

New issue
8000

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

Merged
merged 2 commits into from
Oct 11, 2024
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
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ linters:
- gosec
- misspell
- nakedret
- perfsprint
- paralleltest
- stylecheck
- tparallel
Expand All @@ -24,6 +25,9 @@ linters-settings:
- G104
# int(os.Stdin.Fd())
- G115
perfsprint:
errorf: true
strconcat: false
issues:
exclude-use-default: false
exclude-rules:
Expand Down Expand Up @@ -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'
3 changes: 2 additions & 1 deletion example/codespaces/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"context"
crypto_rand "crypto/rand"
"encoding/base64"
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -84,7 +85,7 @@
func getSecretName() (string, error) {
secretName := flag.Arg(0)
if secretName == "" {
return "", fmt.Errorf("missing argument secret name")
return "", errors.New("missing argument secret name")

Check warning on line 88 in example/codespaces/newreposecretwithxcrypto/main.go

View check run for this annotation

Codecov / codecov/patch

example/codespaces/newreposecretwithxcrypto/main.go#L88

Added line #L88 was not covered by tests
}
return secretName, nil
}
Expand Down
3 changes: 2 additions & 1 deletion example/codespaces/newusersecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"context"
crypto_rand "crypto/rand"
"encoding/base64"
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -77,7 +78,7 @@
func getSecretName() (string, error) {
secretName := flag.Arg(0)
if secretName == "" {
return "", fmt.Errorf("missing argument secret name")
return "", errors.New("missing argument secret name")

Check warning on line 81 in example/codespaces/newusersecretwithxcrypto/main.go

View check run for this annotation

Codecov / codecov/patch

example/codespaces/newusersecretwithxcrypto/main.go#L81

Added line #L81 was not covered by tests
}
return secretName, nil
}
Expand Down
3 changes: 2 additions & 1 deletion example/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"context"
crypto_rand "crypto/rand"
"encoding/base64"
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -84,7 +85,7 @@
func getSecretName() (string, error) {
secretName := flag.Arg(0)
if secretName == "" {
return "", fmt.Errorf("missing argument secret name")
return "", errors.New("missing argument secret name")

Check warning on line 88 in example/newreposecretwithxcrypto/main.go

View check run for this annotation

Codecov / codecov/patch

example/newreposecretwithxcrypto/main.go#L88

Added line #L88 was not covered by tests
}
return secretName, nil
}
Expand Down
3 changes: 2 additions & 1 deletion github/copilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"encoding/json"
"errors"
"fmt"
)

Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion github/git_commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
3 changes: 2 additions & 1 deletion github/git_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion github/orgs_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"encoding/json"
"errors"
"fmt"
)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion github/pulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import (
"bytes"
"context"
"errors"
"fmt"
)

Expand Down Expand Up @@ -352,7 +353,7 @@
//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")

Check warning on line 356 in github/pulls.go

View check run for this annotation

Codecov / codecov/patch

github/pulls.go#L356

Added line #L356 was not covered by tests
}

u := fmt.Sprintf("repos/%v/%v/pulls/%d", owner, repo, number)
Expand Down
9 changes: 5 additions & 4 deletions tools/metadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -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, "")
}
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
Loading
0