Skip to content

Commit 1415544

Browse files
committed
add perfsprint error format
1 parent f8972dd commit 1415544

File tree

103 files changed

+277
-213
lines changed

Some content is hidden

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

103 files changed

+277
-213
lines changed

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- mirror
1717
- nakedret
1818
- nolintlint
19+
- perfsprint
1920
- revive
2021
- staticcheck
2122
- testifylint
@@ -82,6 +83,14 @@ linters:
8283
- name: unreachable-code
8384
- name: var-declaration
8485
- name: var-naming
86+
perfsprint:
87+
integer-format: false
88+
int-conversion: false
89+
string-format: false
90+
sprintf1: false
91+
strconcat: false
92+
bool-format: false
93+
hex-format: false
8594
staticcheck:
8695
checks:
8796
- all

cmd/main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"errors"
78
"fmt"
89
"io"
910
"path/filepath"
@@ -127,7 +128,7 @@ func TestCliCmd(t *testing.T) {
127128
}
128129

129130
func TestCliCmdError(t *testing.T) {
130-
app := newTestApp(func(ctx *cli.Context) error { return fmt.Errorf("normal error") })
131+
app := newTestApp(func(ctx *cli.Context) error { return errors.New("normal error") })
131132
r, err := runTestApp(app, "./gitea", "test-cmd")
132133
assert.Error(t, err)
133134
assert.Equal(t, 1, r.ExitCode)

contrib/backport/backport.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"context"
9+
"errors"
910
"fmt"
1011
"log"
1112
"net/http"
@@ -158,7 +159,7 @@ func runBackport(c *cli.Context) error {
158159

159160
args := c.Args().Slice()
160161
if len(args) == 0 && pr == "" {
161-
return fmt.Errorf("no PR number provided\nProvide a PR number to backport")
162+
return errors.New("no PR number provided\nProvide a PR number to backport")
162163
} else if len(args) != 1 && pr == "" {
163164
return fmt.Errorf("multiple PRs provided %v\nOnly a single PR can be backported at a time", args)
164165
}

models/actions/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package actions
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"slices"
1011
"strings"
@@ -245,7 +246,7 @@ func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID strin
245246

246247
// If the update affected 0 rows, it means the job has changed in the meantime, so we need to try again.
247248
if n == 0 {
248-
return cancelledJobs, fmt.Errorf("job has changed, try again")
249+
return cancelledJobs, errors.New("job has changed, try again")
249250
}
250251

251252
cancelledJobs = append(cancelledJobs, job)
@@ -412,7 +413,7 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
412413
return err
413414
}
414415
if affected == 0 {
415-
return fmt.Errorf("run has changed")
416+
return errors.New("run has changed")
416417
// It's impossible that the run is not found, since Gitea never deletes runs.
417418
}
418419

models/actions/task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package actions
66
import (
77
"context"
88
"crypto/subtle"
9+
"errors"
910
"fmt"
1011
"time"
1112

@@ -361,7 +362,7 @@ func UpdateTaskByState(ctx context.Context, runnerID int64, state *runnerv1.Task
361362
} else if !has {
362363
return nil, util.ErrNotExist
363364
} else if runnerID != task.RunnerID {
364-
return nil, fmt.Errorf("invalid runner for task")
365+
return nil, errors.New("invalid runner for task")
365366
}
366367

367368
if task.Status.IsDone() {

models/activities/action_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package activities
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"strconv"
1011

@@ -205,7 +206,7 @@ func (actions ActionList) LoadIssues(ctx context.Context) error {
205206
// GetFeeds returns actions according to the provided options
206207
func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, error) {
207208
if opts.RequestedUser == nil && opts.RequestedTeam == nil && opts.RequestedRepo == nil {
208-
return nil, 0, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
209+
return nil, 0, errors.New("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
209210
}
210211

211212
var err error

models/asymkey/gpg_key.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package asymkey
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"strings"
1011
"time"
@@ -207,7 +208,7 @@ func parseGPGKey(ctx context.Context, ownerID int64, e *openpgp.Entity, verified
207208
// deleteGPGKey does the actual key deletion
208209
func deleteGPGKey(ctx context.Context, keyID string) (int64, error) {
209210
if keyID == "" {
210-
return 0, fmt.Errorf("empty KeyId forbidden") // Should never happen but just to be sure
211+
return 0, errors.New("empty KeyId forbidden") // Should never happen but just to be sure
211212
}
212213
// Delete imported key
213214
n, err := db.GetEngine(ctx).Where("key_id=?", keyID).Delete(new(GPGKeyImport))

models/asymkey/gpg_key_commit_verification.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package asymkey
55

66
import (
7+
"errors"
78
"fmt"
89
"hash"
910

@@ -68,7 +69,7 @@ const (
6869
func verifySign(s *packet.Signature, h hash.Hash, k *GPGKey) error {
6970
// Check if key can sign
7071
if !k.CanSign {
71-
return fmt.Errorf("key can not sign")
72+
return errors.New("key can not sign")
7273
}
7374
// Decode key
7475
pkey, err := base64DecPubKey(k.Content)

models/asymkey/gpg_key_common.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"crypto"
99
"encoding/base64"
10+
"errors"
1011
"fmt"
1112
"hash"
1213
"io"
@@ -75,7 +76,7 @@ func base64DecPubKey(content string) (*packet.PublicKey, error) {
7576
// Check type
7677
pkey, ok := p.(*packet.PublicKey)
7778
if !ok {
78-
return nil, fmt.Errorf("key is not a public key")
79+
return nil, errors.New("key is not a public key")
7980
}
8081
return pkey, nil
8182
}
@@ -122,15 +123,15 @@ func readArmoredSign(r io.Reader) (body io.Reader, err error) {
122123
func ExtractSignature(s string) (*packet.Signature, error) {
123124
r, err := readArmoredSign(strings.NewReader(s))
124125
if err != nil {
125-
return nil, fmt.Errorf("Failed to read signature armor")
126+
return nil, errors.New("Failed to read signature armor")
126127
}
127128
p, err := packet.Read(r)
128129
if err != nil {
129-
return nil, fmt.Errorf("Failed to read signature packet")
130+
return nil, errors.New("Failed to read signature packet")
130131
}
131132
sig, ok := p.(*packet.Signature)
132133
if !ok {
133-
return nil, fmt.Errorf("Packet is not a signature")
134+
return nil, errors.New("Packet is not a signature")
134135
}
135136
return sig, nil
136137
}

models/asymkey/ssh_key_parse.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/base64"
1111
"encoding/binary"
1212
"encoding/pem"
13+
"errors"
1314
"fmt"
1415
"math/big"
1516
"os"
@@ -93,7 +94,7 @@ func parseKeyString(content string) (string, error) {
9394

9495
block, _ := pem.Decode([]byte(content))
9596
if block == nil {
96-
return "", fmt.Errorf("failed to parse PEM block containing the public key")
97+
return "", errors.New("failed to parse PEM block containing the public key")
9798
}
9899
if strings.Contains(block.Type, "PRIVATE") {
99100
return "", ErrKeyIsPrivate

0 commit comments

Comments
 (0)