Skip to content

Commit ee3c82f

Browse files
Enable addtional linters (#34085)
enable mirror, usestdlibbars and perfsprint part of: #34083 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 56e42be commit ee3c82f

File tree

294 files changed

+848
-805
lines changed

Some content is hidden

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

294 files changed

+848
-805
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ linters:
1313
- gocritic
1414
- govet
1515
- ineffassign
16+
- mirror
1617
- nakedret
1718
- nolintlint
19+
- perfsprint
1820
- revive
1921
- staticcheck
2022
- testifylint
2123
- unconvert
2224
- unparam
2325
- unused
26+
- usestdlibvars
2427
- usetesting
2528
- wastedassign
2629
settings:

cmd/dump.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package cmd
66

77
import (
8-
"fmt"
98
"os"
109
"path"
1110
"path/filepath"
@@ -93,7 +92,7 @@ var CmdDump = &cli.Command{
9392
},
9493
&cli.StringFlag{
9594
Name: "type",
96-
Usage: fmt.Sprintf(`Dump output format, default to "zip", supported types: %s`, strings.Join(dump.SupportedOutputTypes, ", ")),
95+
Usage: `Dump output format, default to "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "),
9796
},
9897
},
9998
}

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)

cmd/serv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func getLFSAuthToken(ctx context.Context, lfsVerb string, results *private.ServC
173173
if err != nil {
174174
return "", fail(ctx, "Failed to sign JWT Token", "Failed to sign JWT token: %v", err)
175175
}
176-
return fmt.Sprintf("Bearer %s", tokenString), nil
176+
return "Bearer " + tokenString, nil
177177
}
178178

179179
func runServ(c *cli.Context) error {
@@ -372,9 +372,9 @@ func runServ(c *cli.Context) error {
372372
repo_module.EnvPusherEmail+"="+results.UserEmail,
373373
repo_module.EnvPusherID+"="+strconv.FormatInt(results.UserID, 10),
374374
repo_module.EnvRepoID+"="+strconv.FormatInt(results.RepoID, 10),
375-
repo_module.EnvPRID+"="+fmt.Sprintf("%d", 0),
376-
repo_module.EnvDeployKeyID+"="+fmt.Sprintf("%d", results.DeployKeyID),
377-
repo_module.EnvKeyID+"="+fmt.Sprintf("%d", results.KeyID),
375+
repo_module.EnvPRID+"="+strconv.Itoa(0),
376+
repo_module.EnvDeployKeyID+"="+strconv.FormatInt(results.DeployKeyID, 10),
377+
repo_module.EnvKeyID+"="+strconv.FormatInt(results.KeyID, 10),
378378
repo_module.EnvAppURL+"="+setting.AppURL,
379379
)
380380
// to avoid breaking, here only use the minimal environment variables for the "gitea serv" command.

cmd/web_acme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func runACME(listenAddr string, m http.Handler) error {
136136
}
137137

138138
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
139-
if r.Method != "GET" && r.Method != "HEAD" {
139+
if r.Method != http.MethodGet && r.Method != http.MethodHead {
140140
http.Error(w, "Use HTTPS", http.StatusBadRequest)
141141
return
142142
}

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/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func IsErrGPGKeyParsing(err error) bool {
132132
}
133133

134134
func (err ErrGPGKeyParsing) Error() string {
135-
return fmt.Sprintf("failed to parse gpg key %s", err.ParseError.Error())
135+
return "failed to parse gpg key " + err.ParseError.Error()
136136
}
137137

138138
// ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.

0 commit comments

Comments
 (0)