Skip to content

Commit 6e2dc94

Browse files
committed
Merge branch 'main' into support-colorblind
2 parents b373900 + dd2aaad commit 6e2dc94

File tree

157 files changed

+411
-443
lines changed

Some content is hidden

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

157 files changed

+411
-443
lines changed

.eslintrc.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ rules:
310310
jquery/no-merge: [2]
311311
jquery/no-param: [2]
312312
jquery/no-parent: [0]
313-
jquery/no-parents: [0]
313+
jquery/no-parents: [2]
314314
jquery/no-parse-html: [2]
315315
jquery/no-prop: [2]
316316
jquery/no-proxy: [2]
@@ -319,8 +319,8 @@ rules:
319319
jquery/no-show: [2]
320320
jquery/no-size: [2]
321321
jquery/no-sizzle: [2]
322-
jquery/no-slide: [0]
323-
jquery/no-submit: [0]
322+
jquery/no-slide: [2]
323+
jquery/no-submit: [2]
324324
jquery/no-text: [0]
325325
jquery/no-toggle: [2]
326326
jquery/no-trigger: [0]
@@ -458,7 +458,7 @@ rules:
458458
no-jquery/no-other-utils: [2]
459459
no-jquery/no-param: [2]
460460
no-jquery/no-parent: [0]
461-
no-jquery/no-parents: [0]
461+
no-jquery/no-parents: [2]
462462
no-jquery/no-parse-html-literal: [0]
463463
no-jquery/no-parse-html: [2]
464464
no-jquery/no-parse-json: [2]

.golangci.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
linters:
2+
enable-all: false
3+
disable-all: true
4+
fast: false
25
enable:
36
- bidichk
4-
# - deadcode # deprecated - https://github.com/golangci/golangci-lint/issues/1841
57
- depguard
68
- dupl
79
- errcheck
810
- forbidigo
911
- gocritic
10-
# - gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
1112
- gofmt
1213
- gofumpt
1314
- gosimple
@@ -17,20 +18,18 @@ linters:
1718
- nolintlint
1819
- revive
1920
- staticcheck
20-
# - structcheck # deprecated - https://github.com/golangci/golangci-lint/issues/1841
2121
- stylecheck
2222
- typecheck
2323
- unconvert
2424
- unused
25-
# - varcheck # deprecated - https://github.com/golangci/golangci-lint/issues/1841
2625
- wastedassign
27-
enable-all: false
28-
disable-all: true
29-
fast: false
3026

3127
run:
3228
timeout: 10m
3329

30+
output:
31+
sort-results: true
32+
3433
linters-settings:
3534
stylecheck:
3635
checks: ["all", "-ST1005", "-ST1003"]
@@ -47,27 +46,37 @@ linters-settings:
4746
errorCode: 1
4847
warningCode: 1
4948
rules:
49+
- name: atomic
50+
- name: bare-return
5051
- name: blank-imports
52+
- name: constant-logical-expr
5153
- name: context-as-argument
5254
- name: context-keys-type
5355
- name: dot-imports
56+
- name: duplicated-imports
57+
- name: empty-lines
58+
- name: error-naming
5459
- name: error-return
5560
- name: error-strings
56-
- name: error-naming
61+
- name: errorf
5762
- name: exported
63+
- name: identical-branches
5864
- name: if-return
5965
- name: increment-decrement
60-
- name: var-naming
61-
- name: var-declaration
66+
- name: indent-error-flow
67+
- name: modifies-value-receiver
6268
- name: package-comments
6369
- name: range
6470
- name: receiver-naming
71+
- name: redefines-builtin-id
72+
- name: string-of-int
73+
- name: superfluous-else
6574
- name: time-naming
75+
- name: unconditional-recursion
6676
- name: unexported-return
67-
- name: indent-error-flow
68-
- name: errorf
69-
- name: duplicated-imports
70-
- name: modifies-value-receiver
77+
- name: unreachable-code
78+
- name: var-declaration
79+
- name: var-naming
7180
gofumpt:
7281
extra-rules: true
7382
depguard:
@@ -93,8 +102,8 @@ issues:
93102
max-issues-per-linter: 0
94103
max-same-issues: 0
95104
exclude-dirs: [node_modules, public, web_src]
105+
exclude-case-sensitive: true
96106
exclude-rules:
97-
# Exclude some linters from running on tests files.
98107
- path: _test\.go
99108
linters:
100109
- gocyclo
@@ -112,19 +121,19 @@ issues:
112121
- path: cmd
113122
linters:
114123
- forbidigo
115-
- linters:
124+
- text: "webhook"
125+
linters:
116126
- dupl
117-
text: "webhook"
118-
- linters:
127+
- text: "`ID' should not be capitalized"
128+
linters:
119129
- gocritic
120-
text: "`ID' should not be capitalized"
121-
- linters:
130+
- text: "swagger"
131+
linters:
122132
- unused
123133
- deadcode
124-
text: "swagger"
125-
- linters:
134+
- text: "argument x is overwritten before first use"
135+
linters:
126136
- staticcheck
127-
text: "argument x is overwritten before first use"
128137
- text: "commentFormatting: put a space between `//` and comment text"
129138
linters:
130139
- gocritic

cmd/admin_auth.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
"os"
910
"text/tabwriter"
@@ -91,7 +92,7 @@ func runListAuth(c *cli.Context) error {
9192

9293
func runDeleteAuth(c *cli.Context) error {
9394
if !c.IsSet("id") {
94-
return fmt.Errorf("--id flag is missing")
95+
return errors.New("--id flag is missing")
9596
}
9697

9798
ctx, cancel := installSignals()

cmd/admin_auth_oauth.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
"net/url"
910

@@ -193,7 +194,7 @@ func runAddOauth(c *cli.Context) error {
193194

194195
func runUpdateOauth(c *cli.Context) error {
195196
if !c.IsSet("id") {
196-
return fmt.Errorf("--id flag is missing")
197+
return errors.New("--id flag is missing")
197198
}
198199

199200
ctx, cancel := installSignals()

cmd/admin_auth_stmp.go

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

66
import (
77
"errors"
8-
"fmt"
98
"strings"
109

1110
auth_model "code.gitea.io/gitea/models/auth"
@@ -166,7 +165,7 @@ func runAddSMTP(c *cli.Context) error {
166165

167166
func runUpdateSMTP(c *cli.Context) error {
168167
if !c.IsSet("id") {
169-
return fmt.Errorf("--id flag is missing")
168+
return errors.New("--id flag is missing")
170169
}
171170

172171
ctx, cancel := installSignals()

cmd/admin_user_delete.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
"strings"
910

@@ -42,7 +43,7 @@ var microcmdUserDelete = &cli.Command{
4243

4344
func runDeleteUser(c *cli.Context) error {
4445
if !c.IsSet("id") && !c.IsSet("username") && !c.IsSet("email") {
45-
return fmt.Errorf("You must provide the id, username or email of a user to delete")
46+
return errors.New("You must provide the id, username or email of a user to delete")
4647
}
4748

4849
ctx, cancel := installSignals()

cmd/admin_user_generate_access_token.go

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

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

910
auth_model "code.gitea.io/gitea/models/auth"
@@ -42,7 +43,7 @@ var microcmdUserGenerateAccessToken = &cli.Command{
4243

4344
func runGenerateAccessToken(c *cli.Context) error {
4445
if !c.IsSet("username") {
45-
return fmt.Errorf("You must provide a username to generate a token for")
46+
return errors.New("You must provide a username to generate a token for")
4647
}
4748

4849
ctx, cancel := installSignals()
@@ -68,7 +69,7 @@ func runGenerateAccessToken(c *cli.Context) error {
6869
return err
6970
}
7071
if exist {
71-
return fmt.Errorf("access token name has been used already")
72+
return errors.New("access token name has been used already")
7273
}
7374

7475
// make sure the scopes are valid

cmd/dump.go

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ var CmdDump = &cli.Command{
8787
Name: "skip-index",
8888
Usage: "Skip bleve index data",
8989
},
90+
&cli.BoolFlag{
91+
Name: "skip-db",
92+
Usage: "Skip database",
93+
},
9094
&cli.StringFlag{
9195
Name: "type",
9296
Usage: fmt.Sprintf(`Dump output format, default to "zip", supported types: %s`, strings.Join(dump.SupportedOutputTypes, ", ")),
@@ -185,35 +189,41 @@ func runDump(ctx *cli.Context) error {
185189
}
186190
}
187191

188-
tmpDir := ctx.String("tempdir")
189-
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
190-
fatal("Path does not exist: %s", tmpDir)
191-
}
192+
if ctx.Bool("skip-db") {
193+
// Ensure that we don't dump the database file that may reside in setting.AppDataPath or elsewhere.
194+
dumper.GlobalExcludeAbsPath(setting.Database.Path)
195+
log.Info("Skipping database")
196+
} else {
197+
tmpDir := ctx.String("tempdir")
198+
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
199+
fatal("Path does not exist: %s", tmpDir)
200+
}
192201

193-
dbDump, err := os.CreateTemp(tmpDir, "gitea-db.sql")
194-
if err != nil {
195-
fatal("Failed to create tmp file: %v", err)
196-
}
197-
defer func() {
198-
_ = dbDump.Close()
199-
if err := util.Remove(dbDump.Name()); err != nil {
200-
log.Warn("Unable to remove temporary file: %s: Error: %v", dbDump.Name(), err)
202+
dbDump, err := os.CreateTemp(tmpDir, "gitea-db.sql")
203+
if err != nil {
204+
fatal("Failed to create tmp file: %v", err)
201205
}
202-
}()
206+
defer func() {
207+
_ = dbDump.Close()
208+
if err := util.Remove(dbDump.Name()); err != nil {
209+
log.Warn("Unable to remove temporary file: %s: Error: %v", dbDump.Name(), err)
210+
}
211+
}()
203212

204-
targetDBType := ctx.String("database")
205-
if len(targetDBType) > 0 && targetDBType != setting.Database.Type.String() {
206-
log.Info("Dumping database %s => %s...", setting.Database.Type, targetDBType)
207-
} else {
208-
log.Info("Dumping database...")
209-
}
213+
targetDBType := ctx.String("database")
214+
if len(targetDBType) > 0 && targetDBType != setting.Database.Type.String() {
215+
log.Info("Dumping database %s => %s...", setting.Database.Type, targetDBType)
216+
} else {
217+
log.Info("Dumping database...")
218+
}
210219

211-
if err := db.DumpDatabase(dbDump.Name(), targetDBType); err != nil {
212-
fatal("Failed to dump database: %v", err)
213-
}
220+
if err := db.DumpDatabase(dbDump.Name(), targetDBType); err != nil {
221+
fatal("Failed to dump database: %v", err)
222+
}
214223

215-
if err = dumper.AddFile("gitea-db.sql", dbDump.Name()); err != nil {
216-
fatal("Failed to include gitea-db.sql: %v", err)
224+
if err = dumper.AddFile("gitea-db.sql", dbDump.Name()); err != nil {
225+
fatal("Failed to include gitea-db.sql: %v", err)
226+
}
217227
}
218228

219229
log.Info("Adding custom configuration file from %s", setting.CustomConf)

cmd/embedded.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ func runViewDo(c *cli.Context) error {
157157
}
158158

159159
if len(matchedAssetFiles) == 0 {
160-
return fmt.Errorf("no files matched the given pattern")
160+
return errors.New("no files matched the given pattern")
161161
} else if len(matchedAssetFiles) > 1 {
162-
return fmt.Errorf("too many files matched the given pattern, try to be more specific")
162+
return errors.New("too many files matched the given pattern, try to be more specific")
163163
}
164164

165165
data, err := matchedAssetFiles[0].fs.ReadFile(matchedAssetFiles[0].name)
@@ -180,7 +180,7 @@ func runExtractDo(c *cli.Context) error {
180180
}
181181

182182
if c.NArg() == 0 {
183-
return fmt.Errorf("a list of pattern of files to extract is mandatory (e.g. '**' for all)")
183+
return errors.New("a list of pattern of files to extract is mandatory (e.g. '**' for all)")
184184
}
185185

186186
destdir := "."

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func hookPrintResult(output, isCreate bool, branch, url string) {
465465
fmt.Fprintf(os.Stderr, " %s\n", url)
466466
}
467467
fmt.Fprintln(os.Stderr, "")
468-
os.Stderr.Sync()
468+
_ = os.Stderr.Sync()
469469
}
470470

471471
func pushOptions() map[string]string {

cmd/manager_logging.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
"os"
910

@@ -249,7 +250,7 @@ func runAddFileLogger(c *cli.Context) error {
249250
if c.IsSet("filename") {
250251
vals["filename"] = c.String("filename")
251252
} else {
252-
return fmt.Errorf("filename must be set when creating a file logger")
253+
return errors.New("filename must be set when creating a file logger")
253254
}
254255
if c.IsSet("rotate") {
255256
vals["rotate"] = c.Bool("rotate")

0 commit comments

Comments
 (0)