Skip to content

Commit 318f360

Browse files
authored
Update go tool dependencies (#19676)
* Update go tool dependencies Updated all tool dependencies to latest tags, hoping CI will like it. * fix new lint errors * handle more strings.Title cases * remove lint skip
1 parent 3c658df commit 318f360

File tree

12 files changed

+30
-18
lines changed

12 files changed

+30
-18
lines changed

.golangci.yml

-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,3 @@ issues:
162162
- path: models/user/openid.go
163163
linters:
164164
- golint
165-
- linters:
166-
- staticcheck
167-
text: "strings.Title is deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead."

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ XGO_VERSION := go-1.18.x
2929
AIR_PACKAGE ?= github.com/cosmtrek/[email protected]
3030
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/[email protected]
3131
ERRCHECK_PACKAGE ?= github.com/kisielk/[email protected]
32-
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected].0
33-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2
32+
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected].1
33+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0
3434
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3535
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
3636
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]

modules/repository/generate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var defaultTransformers = []transformer{
4343
{Name: "PASCAL", Transform: xstrings.ToCamelCase},
4444
{Name: "LOWER", Transform: strings.ToLower},
4545
{Name: "UPPER", Transform: strings.ToUpper},
46-
{Name: "TITLE", Transform: strings.Title},
46+
{Name: "TITLE", Transform: util.ToTitleCase},
4747
}
4848

4949
func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string {

modules/setting/log.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"code.gitea.io/gitea/modules/json"
1717
"code.gitea.io/gitea/modules/log"
18+
"code.gitea.io/gitea/modules/util"
1819

1920
ini "gopkg.in/ini.v1"
2021
)
@@ -245,7 +246,7 @@ func generateNamedLogger(key string, options defaultLogOptions) *LogDescription
245246
Provider: provider,
246247
Config: config,
247248
})
248-
log.Info("%s Log: %s(%s:%s)", strings.Title(key), strings.Title(name), provider, levelName)
249+
log.Info("%s Log: %s(%s:%s)", util.ToTitleCase(key), util.ToTitleCase(name), provider, levelName)
249250
}
250251

251252
AddLogDescription(key, &description)
@@ -331,7 +332,7 @@ func newLogService() {
331332
Provider: provider,
332333
Config: config,
333334
})
334-
log.Info("Gitea Log Mode: %s(%s:%s)", strings.Title(name), strings.Title(provider), levelName)
335+
log.Info("Gitea Log Mode: %s(%s:%s)", util.ToTitleCase(name), util.ToTitleCase(provider), levelName)
335336
}
336337

337338
AddLogDescription(log.DEFAULT, &description)

modules/templates/helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}[\s]*$`)
5252
func NewFuncMap() []template.FuncMap {
5353
return []template.FuncMap{map[string]interface{}{
5454
"GoVer": func() string {
55-
return strings.Title(runtime.Version())
55+
return util.ToTitleCase(runtime.Version())
5656
},
5757
"UseHTTPS": func() bool {
5858
return strings.HasPrefix(setting.AppURL, "https")
@@ -398,7 +398,7 @@ func NewFuncMap() []template.FuncMap {
398398
func NewTextFuncMap() []texttmpl.FuncMap {
399399
return []texttmpl.FuncMap{map[string]interface{}{
400400
"GoVer": func() string {
401-
return strings.Title(runtime.Version())
401+
return util.ToTitleCase(runtime.Version())
402402
},
403403
"AppName": func() string {
404404
return setting.AppName

modules/util/util.go

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
"math/big"
1212
"strconv"
1313
"strings"
14+
15+
"golang.org/x/text/cases"
16+
"golang.org/x/text/language"
1417
)
1518

1619
// OptionalBool a boolean that can be "null"
@@ -181,3 +184,10 @@ func ToUpperASCII(s string) string {
181184
}
182185
return string(b)
183186
}
187+
188+
var titleCaser = cases.Title(language.English)
189+
190+
// ToTitleCase returns s with all english words capitalized
191+
func ToTitleCase(s string) string {
192+
return titleCaser.String(s)
193+
}

modules/util/util_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,8 @@ func BenchmarkToUpper(b *testing.B) {
220220
})
221221
}
222222
}
223+
224+
func TestToTitleCase(t *testing.T) {
225+
assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`)
226+
assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`)
227+
}

routers/init.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"reflect"
1111
"runtime"
1212
"strconv"
13-
"strings"
1413

1514
"code.gitea.io/gitea/models"
1615
asymkey_model "code.gitea.io/gitea/models/asymkey"
@@ -31,6 +30,7 @@ import (
3130
"code.gitea.io/gitea/modules/storage"
3231
"code.gitea.io/gitea/modules/svg"
3332
"code.gitea.io/gitea/modules/translation"
33+
"code.gitea.io/gitea/modules/util"
3434
"code.gitea.io/gitea/modules/web"
3535
packages_router "code.gitea.io/gitea/routers/api/packages"
3636
apiv1 "code.gitea.io/gitea/routers/api/v1"
@@ -111,7 +111,7 @@ func GlobalInitInstalled(ctx context.Context) {
111111
log.Info("Custom path: %s", setting.CustomPath)
112112
log.Info("Log path: %s", setting.LogRootPath)
113113
log.Info("Configuration file: %s", setting.CustomConf)
114-
log.Info("Run Mode: %s", strings.Title(setting.RunMode))
114+
log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode))
115115

116116
// Setup i18n
117117
translation.InitLocales()

routers/web/admin/admin.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"code.gitea.io/gitea/modules/setting"
2727
"code.gitea.io/gitea/modules/timeutil"
2828
"code.gitea.io/gitea/modules/updatechecker"
29+
"code.gitea.io/gitea/modules/util"
2930
"code.gitea.io/gitea/modules/web"
3031
"code.gitea.io/gitea/services/cron"
3132
"code.gitea.io/gitea/services/forms"
@@ -245,7 +246,7 @@ func Config(ctx *context.Context) {
245246
ctx.Data["OfflineMode"] = setting.OfflineMode
246247
ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
247248
ctx.Data["RunUser"] = setting.RunUser
248-
ctx.Data["RunMode"] = strings.Title(setting.RunMode)
249+
ctx.Data["RunMode"] = util.ToTitleCase(setting.RunMode)
249250
if version, err := git.LocalVersion(); err == nil {
250251
ctx.Data["GitVersion"] = version.Original()
251252
}

services/migrations/codebase_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package migrations
66

77
import (
88
"context"
9-
"fmt"
109
"net/url"
1110
"os"
1211
"testing"
@@ -40,7 +39,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
4039
AuthPassword: apiPassword,
4140
})
4241
if err != nil {
43-
t.Fatal(fmt.Sprintf("Error creating Codebase downloader: %v", err))
42+
t.Fatalf("Error creating Codebase downloader: %v", err)
4443
}
4544
repo, err := downloader.GetRepoInfo()
4645
assert.NoError(t, err)

services/migrations/gitlab_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
3434

3535
downloader, err := NewGitlabDownloader(context.Background(), "https://gitlab.com", "gitea/test_repo", "", "", gitlabPersonalAccessToken)
3636
if err != nil {
37-
t.Fatal(fmt.Sprintf("NewGitlabDownloader is nil: %v", err))
37+
t.Fatalf("NewGitlabDownloader is nil: %v", err)
3838
}
3939
repo, err := downloader.GetRepoInfo()
4040
assert.NoError(t, err)

services/migrations/onedev_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package migrations
66

77
import (
88
"context"
9-
"fmt"
109
"net/http"
1110
"net/url"
1211
"testing"
@@ -26,7 +25,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
2625
u, _ := url.Parse("https://code.onedev.io")
2726
downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo")
2827
if err != nil {
29-
t.Fatal(fmt.Sprintf("NewOneDevDownloader is nil: %v", err))
28+
t.Fatalf("NewOneDevDownloader is nil: %v", err)
3029
}
3130
repo, err := downloader.GetRepoInfo()
3231
assert.NoError(t, err)

0 commit comments

Comments
 (0)