Skip to content

Commit b7cfa4e

Browse files
authored
chore: apply golangci "forbidigo" to all packages (#39151)
1 parent 66c672d commit b7cfa4e

17 files changed

Lines changed: 61 additions & 54 deletions

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ linters:
146146
- linters:
147147
- dupl
148148
path: modelmigration/v
149-
- linters:
150-
- forbidigo
151-
path: cmd
152149
- linters:
153150
- dupl
154151
text: (?i)webhook

cmd/actions.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
"context"
8-
"fmt"
98

109
"gitea.dev/modules/private"
1110
"gitea.dev/modules/setting"
@@ -49,6 +48,6 @@ func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
4948
if extra.HasError() {
5049
return handleCliResponseExtra(extra)
5150
}
52-
_, _ = fmt.Printf("%s\n", respText.Text)
51+
cprintln(c, respText.Text)
5352
return nil
5453
}

cmd/admin_user_change_password.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ func runChangePassword(ctx context.Context, c *cli.Command) error {
7373
}
7474
}
7575

76-
fmt.Printf("%s's password has been successfully updated!\n", user.Name)
76+
cprintf(c, "%s's password has been successfully updated!\n", user.Name)
7777
return nil
7878
}

cmd/admin_user_create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func runCreateUser(ctx context.Context, c *cli.Command) error {
152152
return err
153153
}
154154
// codeql[disable-next-line=go/clear-text-logging]
155-
fmt.Printf("generated random password is '%s'\n", password)
155+
cprintf(c, "generated random password is '%s'\n", password)
156156
} else if userType == user_model.UserTypeIndividual {
157157
return errors.New("must set either password or random-password flag")
158158
}
@@ -228,15 +228,15 @@ func runCreateUser(ctx context.Context, c *cli.Command) error {
228228
if err := user_model.CreateUser(ctx, u, &user_model.Meta{}, overwriteDefault); err != nil {
229229
return fmt.Errorf("CreateUser: %w", err)
230230
}
231-
fmt.Printf("New user '%s' has been successfully created!\n", username)
231+
cprintf(c, "New user '%s' has been successfully created!\n", username)
232232

233233
// create the access token
234234
if accessTokenScope != "" {
235235
t := &auth_model.AccessToken{Name: accessTokenName, UID: u.ID, Scope: accessTokenScope}
236236
if err := auth_model.NewAccessToken(ctx, t); err != nil {
237237
return err
238238
}
239-
fmt.Printf("Access token was successfully created... %s\n", t.Token)
239+
cprintf(c, "Access token was successfully created... %s\n", t.Token)
240240
}
241241
return nil
242242
}

cmd/admin_user_disable_2fa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ func runDisableTwoFactor(ctx context.Context, c *cli.Command) error {
6767
return err
6868
}
6969

70-
fmt.Printf("Disabled 2FA for user %q (removed %d TOTP and %d WebAuthn credential(s))\n", user.Name, totp, webAuthn)
70+
cprintf(c, "Disabled 2FA for user %q (removed %d TOTP and %d WebAuthn credential(s))\n", user.Name, totp, webAuthn)
7171
return nil
7272
}

cmd/admin_user_generate_access_token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ func runGenerateAccessToken(ctx context.Context, c *cli.Command) error {
8888
}
8989

9090
if c.Bool("raw") {
91-
fmt.Printf("%s\n", t.Token)
91+
cprintln(c, t.Token)
9292
} else {
93-
fmt.Printf("Access token was successfully created: %s\n", t.Token)
93+
cprintf(c, "Access token was successfully created: %s\n", t.Token)
9494
}
9595

9696
return nil

cmd/admin_user_must_change_password.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cmd
66
import (
77
"context"
88
"errors"
9-
"fmt"
109

1110
user_model "gitea.dev/models/user"
1211
"gitea.dev/modules/setting"
@@ -59,6 +58,6 @@ func runMustChangePassword(ctx context.Context, c *cli.Command) error {
5958
}
6059

6160
// codeql[disable-next-line=go/clear-text-logging]
62-
fmt.Printf("Updated %d users setting MustChangePassword to %t\n", n, mustChangePassword)
61+
cprintf(c, "Updated %d users setting MustChangePassword to %t\n", n, mustChangePassword)
6362
return nil
6463
}

cmd/doctor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ func runRecreateTable(ctx context.Context, cmd *cli.Command) error {
114114

115115
setting.Database.LogSQL = debug
116116
if err := db.InitEngine(ctx); err != nil {
117-
fmt.Println(err)
118-
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
117+
cprintln(cmd, err)
118+
cprintln(cmd, "Check if you are using the right config file. You can use a --config directive to specify one.")
119119
return nil
120120
}
121121

cmd/doctor_convert.go

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

66
import (
77
"context"
8-
"fmt"
98

109
"gitea.dev/models/db"
1110
"gitea.dev/modules/log"
@@ -40,15 +39,15 @@ func runDoctorConvert(ctx context.Context, cmd *cli.Command) error {
4039
log.Fatal("Failed to convert database & table: %v", err)
4140
return err
4241
}
43-
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
42+
cprintln(cmd, "Converted successfully, please confirm your database's character set is now utf8mb4")
4443
case setting.Database.Type.IsMSSQL():
4544
if err := db.ConvertVarcharToNVarchar(); err != nil {
4645
log.Fatal("Failed to convert database from varchar to nvarchar: %v", err)
4746
return err
4847
}
49-
fmt.Println("Converted successfully, please confirm your database's all columns character is NVARCHAR now")
48+
cprintln(cmd, "Converted successfully, please confirm your database's all columns character is NVARCHAR now")
5049
default:
51-
fmt.Println("This command can only be used with a MySQL or MSSQL database")
50+
cprintln(cmd, "This command can only be used with a MySQL or MSSQL database")
5251
}
5352

5453
return nil

cmd/embedded.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func runListDo(c *cli.Command) error {
150150
}
151151

152152
for _, a := range matchedAssetFiles {
153-
fmt.Println(a.path)
153+
cprintln(c, a.path)
154154
}
155155

156156
return nil
@@ -194,7 +194,7 @@ func runExtractDo(c *cli.Command) error {
194194
destdir = c.String("destination")
195195
} else if c.Bool("custom") {
196196
destdir = setting.CustomPath
197-
fmt.Println("Using app.ini at", setting.CustomConf)
197+
cprintln(c, "Using app.ini at", setting.CustomConf)
198198
}
199199

200200
fi, err := os.Stat(destdir)
@@ -213,13 +213,13 @@ func runExtractDo(c *cli.Command) error {
213213
return fmt.Errorf("destination %q is not a directory", destdir)
214214
}
215215

216-
fmt.Printf("Extracting to %s:\n", destdir)
216+
cprintf(c, "Extracting to %s:\n", destdir)
217217

218218
overwrite := c.Bool("overwrite")
219219
rename := c.Bool("rename")
220220

221221
for _, a := range matchedAssetFiles {
222-
if err := extractAsset(destdir, a, overwrite, rename); err != nil {
222+
if err := extractAsset(c, destdir, a, overwrite, rename); err != nil {
223223
// Non-fatal error
224224
_, _ = fmt.Fprintf(os.Stderr, "%s: %v\n", a.path, err)
225225
}
@@ -228,7 +228,7 @@ func runExtractDo(c *cli.Command) error {
228228
return nil
229229
}
230230

231-
func extractAsset(d string, a assetFile, overwrite, rename bool) error {
231+
func extractAsset(c *cli.Command, d string, a assetFile, overwrite, rename bool) error {
232232
dest := filepath.Join(d, filepath.FromSlash(a.path))
233233
dir := filepath.Dir(dest)
234234

@@ -249,7 +249,7 @@ func extractAsset(d string, a assetFile, overwrite, rename bool) error {
249249
return fmt.Errorf("%s: %w", dest, err)
250250
}
251251
} else if !overwrite && !rename {
252-
fmt.Printf("%s already exists; skipped.\n", dest)
252+
cprintf(c, "%s already exists; skipped.\n", dest)
253253
return nil
254254
} else if !fi.Mode().IsRegular() {
255255
return fmt.Errorf("%s already exists, but it's not a regular file", dest)
@@ -271,7 +271,7 @@ func extractAsset(d string, a assetFile, overwrite, rename bool) error {
271271
return fmt.Errorf("%s: %w", dest, err)
272272
}
273273

274-
fmt.Println(dest)
274+
cprintln(c, dest)
275275

276276
return nil
277277
}
@@ -306,7 +306,7 @@ func compileCollectPatterns(args []string) (_ []glob.Glob, err error) {
306306
pat := make([]glob.Glob, len(args))
307307
for i := range args {
308308
if pat[i], err = glob.Compile(args[i], '/'); err != nil {
309-
return nil, fmt.Errorf("invalid glob patterh %q: %w", args[i], err)
309+
return nil, fmt.Errorf("invalid glob pattern %q: %w", args[i], err)
310310
}
311311
}
312312
return pat, nil

0 commit comments

Comments
 (0)