Skip to content

Commit aa9d867

Browse files
enforce explanation for necessary nolints and fix bugs (#34883)
Follows up #34851 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 9854df3 commit aa9d867

File tree

48 files changed

+83
-159
lines changed

Some content is hidden

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

48 files changed

+83
-159
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ linters:
4646
- pkg: gitea.com/go-chi/cache
4747
desc: do not use the go-chi cache package, use gitea's cache system
4848
nolintlint:
49-
# require-explanation: true
49+
allow-unused: false
50+
require-explanation: true
5051
require-specific: true
5152
gocritic:
5253
disabled-checks:

cmd/embedded.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,14 @@ func collectAssetFilesByPattern(c *cli.Command, globs []glob.Glob, path string,
295295
}
296296
}
297297

298-
func compileCollectPatterns(args []string) ([]glob.Glob, error) {
298+
func compileCollectPatterns(args []string) (_ []glob.Glob, err error) {
299299
if len(args) == 0 {
300300
args = []string{"**"}
301301
}
302302
pat := make([]glob.Glob, len(args))
303303
for i := range args {
304-
if g, err := glob.Compile(args[i], '/'); err != nil {
305-
return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
306-
} else { //nolint:revive
307-
pat[i] = g
304+
if pat[i], err = glob.Compile(args[i], '/'); err != nil {
305+
return nil, fmt.Errorf("invalid glob patterh %q: %w", args[i], err)
308306
}
309307
}
310308
return pat, nil

contrib/backport/backport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2023 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//nolint:forbidigo
4+
//nolint:forbidigo // use of print functions is allowed in cli
55
package main
66

77
import (

models/actions/task.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
278278
return nil, false, err
279279
}
280280

281-
var workflowJob *jobparser.Job
282-
if gots, err := jobparser.Parse(job.WorkflowPayload); err != nil {
281+
parsedWorkflows, err := jobparser.Parse(job.WorkflowPayload)
282+
if err != nil {
283283
return nil, false, fmt.Errorf("parse workflow of job %d: %w", job.ID, err)
284-
} else if len(gots) != 1 {
284+
} else if len(parsedWorkflows) != 1 {
285285
return nil, false, fmt.Errorf("workflow of job %d: not single workflow", job.ID)
286-
} else { //nolint:revive
287-
_, workflowJob = gots[0].Job()
288286
}
287+
_, workflowJob := parsedWorkflows[0].Job()
289288

290289
if _, err := e.Insert(task); err != nil {
291290
return nil, false, err

models/auth/auth_token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
var ErrAuthTokenNotExist = util.NewNotExistErrorf("auth token does not exist")
1717

18-
type AuthToken struct { //nolint:revive
18+
type AuthToken struct { //nolint:revive // export stutter
1919
ID string `xorm:"pk"`
2020
TokenHash string
2121
UserID int64 `xorm:"INDEX"`

models/db/sql_postgres_with_schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
3939

4040
// golangci lint is incorrect here - there is no benefit to using driver.ExecerContext here
4141
// and in any case pq does not implement it
42-
if execer, ok := conn.(driver.Execer); ok { //nolint:staticcheck
42+
if execer, ok := conn.(driver.Execer); ok { //nolint:staticcheck // see above
4343
_, err := execer.Exec(`SELECT set_config(
4444
'search_path',
4545
$1 || ',' || current_setting('search_path'),
@@ -64,7 +64,7 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
6464
// driver.String.ConvertValue will never return err for string
6565

6666
// golangci lint is incorrect here - there is no benefit to using stmt.ExecWithContext here
67-
_, err = stmt.Exec([]driver.Value{schemaValue}) //nolint:staticcheck
67+
_, err = stmt.Exec([]driver.Value{schemaValue}) //nolint:staticcheck // see above
6868
if err != nil {
6969
_ = conn.Close()
7070
return nil, err

models/migrations/base/tests.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2022 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//nolint:forbidigo
54
package base
65

76
import (
@@ -106,7 +105,7 @@ func MainTest(m *testing.M) {
106105
giteaConf := os.Getenv("GITEA_CONF")
107106
if giteaConf == "" {
108107
giteaConf = filepath.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini")
109-
fmt.Printf("Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf)
108+
_, _ = fmt.Fprintf(os.Stderr, "Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf)
110109
}
111110

112111
if !filepath.IsAbs(giteaConf) {
@@ -134,7 +133,7 @@ func MainTest(m *testing.M) {
134133
exitStatus := m.Run()
135134

136135
if err := removeAllWithRetry(setting.RepoRootPath); err != nil {
137-
fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
136+
_, _ = fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
138137
}
139138
os.Exit(exitStatus)
140139
}

models/migrations/v1_11/v112.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
package v1_11
55

66
import (
7-
"fmt"
87
"path/filepath"
98

9+
"code.gitea.io/gitea/modules/log"
1010
"code.gitea.io/gitea/modules/setting"
1111
"code.gitea.io/gitea/modules/util"
1212

@@ -31,7 +31,7 @@ func RemoveAttachmentMissedRepo(x *xorm.Engine) error {
3131
for i := 0; i < len(attachments); i++ {
3232
uuid := attachments[i].UUID
3333
if err = util.RemoveAll(filepath.Join(setting.Attachment.Storage.Path, uuid[0:1], uuid[1:2], uuid)); err != nil {
34-
fmt.Printf("Error: %v", err) //nolint:forbidigo
34+
log.Warn("Unable to remove attachment file by UUID %s: %v", uuid, err)
3535
}
3636
}
3737

models/migrations/v1_13/v140.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ func FixLanguageStatsToSaveSize(x *xorm.Engine) error {
2121
// RepoIndexerType specifies the repository indexer type
2222
type RepoIndexerType int
2323

24-
const (
25-
// RepoIndexerTypeCode code indexer - 0
26-
RepoIndexerTypeCode RepoIndexerType = iota //nolint:unused
27-
// RepoIndexerTypeStats repository stats indexer - 1
28-
RepoIndexerTypeStats
29-
)
24+
const RepoIndexerTypeStats RepoIndexerType = 1
3025

3126
// RepoIndexerStatus see models/repo_indexer.go
3227
type RepoIndexerStatus struct {

models/migrations/v1_14/v157.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ import (
88
)
99

1010
func FixRepoTopics(x *xorm.Engine) error {
11-
type Topic struct { //nolint:unused
12-
ID int64 `xorm:"pk autoincr"`
13-
Name string `xorm:"UNIQUE VARCHAR(25)"`
14-
RepoCount int
15-
}
16-
17-
type RepoTopic struct { //nolint:unused
18-
RepoID int64 `xorm:"pk"`
19-
TopicID int64 `xorm:"pk"`
20-
}
21-
2211
type Repository struct {
2312
ID int64 `xorm:"pk autoincr"`
2413
Topics []string `xorm:"TEXT JSON"`

0 commit comments

Comments
 (0)