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
This commit is contained in:
silverwind 2022-05-10 23:55:54 +02:00 committed by GitHub
parent 3c658dff23
commit 318f360252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 30 additions and 18 deletions

View File

@ -162,6 +162,3 @@ issues:
- path: models/user/openid.go - path: models/user/openid.go
linters: linters:
- golint - golint
- linters:
- staticcheck
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."

View File

@ -29,8 +29,8 @@ XGO_VERSION := go-1.18.x
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.29.0 AIR_PACKAGE ?= github.com/cosmtrek/air@v1.29.0
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.4.0 EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.4.0
ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@v1.6.0 ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@v1.6.0
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.3.0 GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.3.1
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2 GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10 GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4 MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.29.0 SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.29.0

View File

@ -43,7 +43,7 @@ var defaultTransformers = []transformer{
{Name: "PASCAL", Transform: xstrings.ToCamelCase}, {Name: "PASCAL", Transform: xstrings.ToCamelCase},
{Name: "LOWER", Transform: strings.ToLower}, {Name: "LOWER", Transform: strings.ToLower},
{Name: "UPPER", Transform: strings.ToUpper}, {Name: "UPPER", Transform: strings.ToUpper},
{Name: "TITLE", Transform: strings.Title}, {Name: "TITLE", Transform: util.ToTitleCase},
} }
func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string { func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string {

View File

@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
ini "gopkg.in/ini.v1" ini "gopkg.in/ini.v1"
) )
@ -245,7 +246,7 @@ func generateNamedLogger(key string, options defaultLogOptions) *LogDescription
Provider: provider, Provider: provider,
Config: config, Config: config,
}) })
log.Info("%s Log: %s(%s:%s)", strings.Title(key), strings.Title(name), provider, levelName) log.Info("%s Log: %s(%s:%s)", util.ToTitleCase(key), util.ToTitleCase(name), provider, levelName)
} }
AddLogDescription(key, &description) AddLogDescription(key, &description)
@ -331,7 +332,7 @@ func newLogService() {
Provider: provider, Provider: provider,
Config: config, Config: config,
}) })
log.Info("Gitea Log Mode: %s(%s:%s)", strings.Title(name), strings.Title(provider), levelName) log.Info("Gitea Log Mode: %s(%s:%s)", util.ToTitleCase(name), util.ToTitleCase(provider), levelName)
} }
AddLogDescription(log.DEFAULT, &description) AddLogDescription(log.DEFAULT, &description)

View File

@ -52,7 +52,7 @@ var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}[\s]*$`)
func NewFuncMap() []template.FuncMap { func NewFuncMap() []template.FuncMap {
return []template.FuncMap{map[string]interface{}{ return []template.FuncMap{map[string]interface{}{
"GoVer": func() string { "GoVer": func() string {
return strings.Title(runtime.Version()) return util.ToTitleCase(runtime.Version())
}, },
"UseHTTPS": func() bool { "UseHTTPS": func() bool {
return strings.HasPrefix(setting.AppURL, "https") return strings.HasPrefix(setting.AppURL, "https")
@ -398,7 +398,7 @@ func NewFuncMap() []template.FuncMap {
func NewTextFuncMap() []texttmpl.FuncMap { func NewTextFuncMap() []texttmpl.FuncMap {
return []texttmpl.FuncMap{map[string]interface{}{ return []texttmpl.FuncMap{map[string]interface{}{
"GoVer": func() string { "GoVer": func() string {
return strings.Title(runtime.Version()) return util.ToTitleCase(runtime.Version())
}, },
"AppName": func() string { "AppName": func() string {
return setting.AppName return setting.AppName

View File

@ -11,6 +11,9 @@ import (
"math/big" "math/big"
"strconv" "strconv"
"strings" "strings"
"golang.org/x/text/cases"
"golang.org/x/text/language"
) )
// OptionalBool a boolean that can be "null" // OptionalBool a boolean that can be "null"
@ -181,3 +184,10 @@ func ToUpperASCII(s string) string {
} }
return string(b) return string(b)
} }
var titleCaser = cases.Title(language.English)
// ToTitleCase returns s with all english words capitalized
func ToTitleCase(s string) string {
return titleCaser.String(s)
}

View File

@ -220,3 +220,8 @@ func BenchmarkToUpper(b *testing.B) {
}) })
} }
} }
func TestToTitleCase(t *testing.T) {
assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`)
assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`)
}

View File

@ -10,7 +10,6 @@ import (
"reflect" "reflect"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey" asymkey_model "code.gitea.io/gitea/models/asymkey"
@ -31,6 +30,7 @@ import (
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/svg" "code.gitea.io/gitea/modules/svg"
"code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
packages_router "code.gitea.io/gitea/routers/api/packages" packages_router "code.gitea.io/gitea/routers/api/packages"
apiv1 "code.gitea.io/gitea/routers/api/v1" apiv1 "code.gitea.io/gitea/routers/api/v1"
@ -111,7 +111,7 @@ func GlobalInitInstalled(ctx context.Context) {
log.Info("Custom path: %s", setting.CustomPath) log.Info("Custom path: %s", setting.CustomPath)
log.Info("Log path: %s", setting.LogRootPath) log.Info("Log path: %s", setting.LogRootPath)
log.Info("Configuration file: %s", setting.CustomConf) log.Info("Configuration file: %s", setting.CustomConf)
log.Info("Run Mode: %s", strings.Title(setting.RunMode)) log.Info("Run Mode: %s", util.ToTitleCase(setting.RunMode))
// Setup i18n // Setup i18n
translation.InitLocales() translation.InitLocales()

View File

@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/updatechecker" "code.gitea.io/gitea/modules/updatechecker"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/cron" "code.gitea.io/gitea/services/cron"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
@ -245,7 +246,7 @@ func Config(ctx *context.Context) {
ctx.Data["OfflineMode"] = setting.OfflineMode ctx.Data["OfflineMode"] = setting.OfflineMode
ctx.Data["DisableRouterLog"] = setting.DisableRouterLog ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
ctx.Data["RunUser"] = setting.RunUser ctx.Data["RunUser"] = setting.RunUser
ctx.Data["RunMode"] = strings.Title(setting.RunMode) ctx.Data["RunMode"] = util.ToTitleCase(setting.RunMode)
if version, err := git.LocalVersion(); err == nil { if version, err := git.LocalVersion(); err == nil {
ctx.Data["GitVersion"] = version.Original() ctx.Data["GitVersion"] = version.Original()
} }

View File

@ -6,7 +6,6 @@ package migrations
import ( import (
"context" "context"
"fmt"
"net/url" "net/url"
"os" "os"
"testing" "testing"
@ -40,7 +39,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
AuthPassword: apiPassword, AuthPassword: apiPassword,
}) })
if err != nil { if err != nil {
t.Fatal(fmt.Sprintf("Error creating Codebase downloader: %v", err)) t.Fatalf("Error creating Codebase downloader: %v", err)
} }
repo, err := downloader.GetRepoInfo() repo, err := downloader.GetRepoInfo()
assert.NoError(t, err) assert.NoError(t, err)

View File

@ -34,7 +34,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
downloader, err := NewGitlabDownloader(context.Background(), "https://gitlab.com", "gitea/test_repo", "", "", gitlabPersonalAccessToken) downloader, err := NewGitlabDownloader(context.Background(), "https://gitlab.com", "gitea/test_repo", "", "", gitlabPersonalAccessToken)
if err != nil { if err != nil {
t.Fatal(fmt.Sprintf("NewGitlabDownloader is nil: %v", err)) t.Fatalf("NewGitlabDownloader is nil: %v", err)
} }
repo, err := downloader.GetRepoInfo() repo, err := downloader.GetRepoInfo()
assert.NoError(t, err) assert.NoError(t, err)

View File

@ -6,7 +6,6 @@ package migrations
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"testing" "testing"
@ -26,7 +25,7 @@ func TestOneDevDownloadRepo(t *testing.T) {
u, _ := url.Parse("https://code.onedev.io") u, _ := url.Parse("https://code.onedev.io")
downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo") downloader := NewOneDevDownloader(context.Background(), u, "", "", "go-gitea-test_repo")
if err != nil { if err != nil {
t.Fatal(fmt.Sprintf("NewOneDevDownloader is nil: %v", err)) t.Fatalf("NewOneDevDownloader is nil: %v", err)
} }
repo, err := downloader.GetRepoInfo() repo, err := downloader.GetRepoInfo()
assert.NoError(t, err) assert.NoError(t, err)