Skip to content

Commit 2a59dfb

Browse files
authored
enable staticcheck QFxxxx rules (#34064)
1 parent 5564c39 commit 2a59dfb

File tree

47 files changed

+179
-143
lines changed

Some content is hidden

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

47 files changed

+179
-143
lines changed

.golangci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,8 @@ linters:
8686
- -ST1003
8787
- -ST1005
8888
- -QF1001
89-
- -QF1002
90-
- -QF1003
9189
- -QF1006
92-
- -QF1007
9390
- -QF1008
94-
- -QF1009
95-
- -QF1012
9691
testifylint:
9792
disable:
9893
- go-require

cmd/doctor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ func setupDoctorDefaultLogger(ctx *cli.Context, colorize bool) {
144144
setupConsoleLogger(log.FATAL, log.CanColorStderr, os.Stderr)
145145

146146
logFile := ctx.String("log-file")
147-
if logFile == "" {
147+
switch logFile {
148+
case "":
148149
return // if no doctor log-file is set, do not show any log from default logger
149-
} else if logFile == "-" {
150+
case "-":
150151
setupConsoleLogger(log.TRACE, colorize, os.Stdout)
151-
} else {
152+
default:
152153
logFile, _ = filepath.Abs(logFile)
153154
writeMode := log.WriterMode{Level: log.TRACE, WriterOption: log.WriterFileOption{FileName: logFile}}
154155
writer, err := log.NewEventWriter("console-to-file", "file", writeMode)

models/actions/runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ func (r *ActionRunner) BelongsToOwnerType() types.OwnerType {
8686
return types.OwnerTypeRepository
8787
}
8888
if r.OwnerID != 0 {
89-
if r.Owner.Type == user_model.UserTypeOrganization {
89+
switch r.Owner.Type {
90+
case user_model.UserTypeOrganization:
9091
return types.OwnerTypeOrganization
91-
} else if r.Owner.Type == user_model.UserTypeIndividual {
92+
case user_model.UserTypeIndividual:
9293
return types.OwnerTypeIndividual
9394
}
9495
}

models/db/engine_init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ func newXORMEngine() (*xorm.Engine, error) {
4242
if err != nil {
4343
return nil, err
4444
}
45-
if setting.Database.Type == "mysql" {
45+
switch setting.Database.Type {
46+
case "mysql":
4647
engine.Dialect().SetParams(map[string]string{"rowFormat": "DYNAMIC"})
47-
} else if setting.Database.Type == "mssql" {
48+
case "mssql":
4849
engine.Dialect().SetParams(map[string]string{"DEFAULT_VARCHAR": "nvarchar"})
4950
}
5051
engine.SetSchema(setting.Database.Schema)

models/repo/repo.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,32 +425,33 @@ func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit
425425
return ru
426426
}
427427

428-
if tp == unit.TypeExternalWiki {
428+
switch tp {
429+
case unit.TypeExternalWiki:
429430
return &RepoUnit{
430431
Type: tp,
431432
Config: new(ExternalWikiConfig),
432433
}
433-
} else if tp == unit.TypeExternalTracker {
434+
case unit.TypeExternalTracker:
434435
return &RepoUnit{
435436
Type: tp,
436437
Config: new(ExternalTrackerConfig),
437438
}
438-
} else if tp == unit.TypePullRequests {
439+
case unit.TypePullRequests:
439440
return &RepoUnit{
440441
Type: tp,
441442
Config: new(PullRequestsConfig),
442443
}
443-
} else if tp == unit.TypeIssues {
444+
case unit.TypeIssues:
444445
return &RepoUnit{
445446
Type: tp,
446447
Config: new(IssuesConfig),
447448
}
448-
} else if tp == unit.TypeActions {
449+
case unit.TypeActions:
449450
return &RepoUnit{
450451
Type: tp,
451452
Config: new(ActionsConfig),
452453
}
453-
} else if tp == unit.TypeProjects {
454+
case unit.TypeProjects:
454455
cfg := new(ProjectsConfig)
455456
cfg.ProjectsMode = ProjectsModeNone
456457
return &RepoUnit{

models/unittest/fscopy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func SyncFile(srcPath, destPath string) error {
2828
}
2929

3030
if src.Size() == dest.Size() &&
31-
src.ModTime() == dest.ModTime() &&
31+
src.ModTime().Equal(dest.ModTime()) &&
3232
src.Mode() == dest.Mode() {
3333
return nil
3434
}

models/user/search.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Sess
4545
var cond builder.Cond
4646
cond = builder.Eq{"type": opts.Type}
4747
if opts.IncludeReserved {
48-
if opts.Type == UserTypeIndividual {
48+
switch opts.Type {
49+
case UserTypeIndividual:
4950
cond = cond.Or(builder.Eq{"type": UserTypeUserReserved}).Or(
5051
builder.Eq{"type": UserTypeBot},
5152
).Or(
5253
builder.Eq{"type": UserTypeRemoteUser},
5354
)
54-
} else if opts.Type == UserTypeOrganization {
55+
case UserTypeOrganization:
5556
cond = cond.Or(builder.Eq{"type": UserTypeOrganizationReserved})
5657
}
5758
}

models/webhook/hooktask.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ func MarkTaskDelivered(ctx context.Context, task *HookTask) (bool, error) {
198198
func CleanupHookTaskTable(ctx context.Context, cleanupType HookTaskCleanupType, olderThan time.Duration, numberToKeep int) error {
199199
log.Trace("Doing: CleanupHookTaskTable")
200200

201-
if cleanupType == OlderThan {
201+
switch cleanupType {
202+
case OlderThan:
202203
deleteOlderThan := time.Now().Add(-olderThan).UnixNano()
203204
deletes, err := db.GetEngine(ctx).
204205
Where("is_delivered = ? and delivered < ?", true, deleteOlderThan).
@@ -207,7 +208,7 @@ func CleanupHookTaskTable(ctx context.Context, cleanupType HookTaskCleanupType,
207208
return err
208209
}
209210
log.Trace("Deleted %d rows from hook_task", deletes)
210-
} else if cleanupType == PerWebhook {
211+
case PerWebhook:
211212
hookIDs := make([]int64, 0, 10)
212213
err := db.GetEngine(ctx).
213214
Table("webhook").

modules/git/grep.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
6262
var results []*GrepResult
6363
cmd := NewCommand("grep", "--null", "--break", "--heading", "--line-number", "--full-name")
6464
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
65-
if opts.GrepMode == GrepModeExact {
65+
switch opts.GrepMode {
66+
case GrepModeExact:
6667
cmd.AddArguments("--fixed-strings")
6768
cmd.AddOptionValues("-e", strings.TrimLeft(search, "-"))
68-
} else if opts.GrepMode == GrepModeRegexp {
69+
case GrepModeRegexp:
6970
cmd.AddArguments("--perl-regexp")
7071
cmd.AddOptionValues("-e", strings.TrimLeft(search, "-"))
71-
} else /* words */ {
72+
default: /* words */
7273
words := strings.Fields(search)
7374
cmd.AddArguments("--fixed-strings", "--ignore-case")
7475
for i, word := range words {

modules/git/log_name_status.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int
118118
g.buffull = false
119119
g.next, err = g.rd.ReadSlice('\x00')
120120
if err != nil {
121-
if err == bufio.ErrBufferFull {
121+
switch err {
122+
case bufio.ErrBufferFull:
122123
g.buffull = true
123-
} else if err == io.EOF {
124+
case io.EOF:
124125
return nil, nil
125-
} else {
126+
default:
126127
return nil, err
127128
}
128129
}
@@ -132,11 +133,12 @@ func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int
132133
if bytes.Equal(g.next, []byte("commit\000")) {
133134
g.next, err = g.rd.ReadSlice('\x00')
134135
if err != nil {
135-
if err == bufio.ErrBufferFull {
136+
switch err {
137+
case bufio.ErrBufferFull:
136138
g.buffull = true
137-
} else if err == io.EOF {
139+
case io.EOF:
138140
return nil, nil
139-
} else {
141+
default:
140142
return nil, err
141143
}
142144
}
@@ -214,11 +216,12 @@ diffloop:
214216
}
215217
g.next, err = g.rd.ReadSlice('\x00')
216218
if err != nil {
217-
if err == bufio.ErrBufferFull {
219+
switch err {
220+
case bufio.ErrBufferFull:
218221
g.buffull = true
219-
} else if err == io.EOF {
222+
case io.EOF:
220223
return &ret, nil
221-
} else {
224+
default:
222225
return nil, err
223226
}
224227
}

0 commit comments

Comments
 (0)