Skip to content

Commit ea0fe83

Browse files
author
Gusted
authored
Fix golangci-lint warnings (#17598 et al) (#17668)
Backport #17598 Backport #17606 Backport #17608 Backport #17609 - Since https://gitea.com/gitea/test-env/pulls/10 the golangci-lint has been upgraded and is erroring about new warnings in the code, this PR fixes those warnings.
1 parent 1cec7f5 commit ea0fe83

File tree

96 files changed

+139
-64
lines changed

Some content is hidden

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

96 files changed

+139
-64
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ linters:
99
- unused
1010
- structcheck
1111
- varcheck
12-
- golint
1312
- dupl
1413
#- gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
1514
- gofmt

build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
//+build vendor
5+
//go:build vendor
6+
// +build vendor
67

78
package main
89

build/generate-bindata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build ignore
56
// +build ignore
67

78
package main

build/generate-emoji.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build ignore
67
// +build ignore
78

89
package main

build/generate-gitignores.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ignore
12
// +build ignore
23

34
package main

build/generate-licenses.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build ignore
12
// +build ignore
23

34
package main

build/gocovmerge.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// gocovmerge takes the results from multiple `go test -coverprofile` runs and
77
// merges them into one profile
88

9+
//go:build ignore
910
// +build ignore
1011

1112
package main

cmd/docs.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func runDocs(ctx *cli.Context) error {
4343
// Clean up markdown. The following bug was fixed in v2, but is present in v1.
4444
// It affects markdown output (even though the issue is referring to man pages)
4545
// https://github.com/urfave/cli/issues/1040
46-
docs = docs[strings.Index(docs, "#"):]
46+
firstHashtagIndex := strings.Index(docs, "#")
47+
48+
if firstHashtagIndex > 0 {
49+
docs = docs[firstHashtagIndex:]
50+
}
4751
}
4852

4953
out := os.Stdout

cmd/embedded.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build bindata
56
// +build bindata
67

78
package cmd

cmd/embedded_stub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !bindata
56
// +build !bindata
67

78
package cmd

models/migrations/migrations.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package migrations
77

88
import (
99
"context"
10+
"errors"
1011
"fmt"
1112
"os"
1213
"reflect"
@@ -762,8 +763,14 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
762763
}
763764
tableSQL := string(res[0]["sql"])
764765

766+
// Get the string offset for column definitions: `CREATE TABLE ( column-definitions... )`
767+
columnDefinitionsIndex := strings.Index(tableSQL, "(")
768+
if columnDefinitionsIndex < 0 {
769+
return errors.New("couldn't find column definitions")
770+
}
771+
765772
// Separate out the column definitions
766-
tableSQL = tableSQL[strings.Index(tableSQL, "("):]
773+
tableSQL = tableSQL[columnDefinitionsIndex:]
767774

768775
// Remove the required columnNames
769776
for _, name := range columnNames {

modules/auth/pam/pam.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pam
12
// +build pam
23

34
// Copyright 2014 The Gogs Authors. All rights reserved.

modules/auth/pam/pam_stub.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// +build !pam
2-
31
// Copyright 2014 The Gogs Authors. All rights reserved.
42
// Use of this source code is governed by a MIT-style
53
// license that can be found in the LICENSE file.
64

5+
//go:build !pam
6+
// +build !pam
7+
78
package pam
89

910
import (

modules/auth/pam/pam_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pam
12
// +build pam
23

34
// Copyright 2021 The Gitea Authors. All rights reserved.

modules/git/blob_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/blob_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/command_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build race
56
// +build race
67

78
package git

modules/git/commit_convert_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/commit_info_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/commit_info_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/last_commit_cache_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/last_commit_cache_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/notes_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/notes_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/parse_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/parse_gogit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/parse_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/parse_nogogit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/pipeline/lfs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package pipeline

modules/git/pipeline/lfs_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package pipeline

modules/git/repo_base_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/repo_base_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build !gogit
67
// +build !gogit
78

89
package git

modules/git/repo_blob_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/repo_blob_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/repo_branch_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/repo_branch_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build !gogit
67
// +build !gogit
78

89
package git

modules/git/repo_commit_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/repo_commit_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/repo_commitgraph_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/repo_language_stats_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/repo_language_stats_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/repo_ref_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build gogit
56
// +build gogit
67

78
package git

modules/git/repo_ref_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/repo_tag_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/repo_tag_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build !gogit
67
// +build !gogit
78

89
package git

modules/git/repo_tree_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

modules/git/repo_tree_nogogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !gogit
56
// +build !gogit
67

78
package git

modules/git/sha1_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build gogit
67
// +build gogit
78

89
package git

0 commit comments

Comments
 (0)