aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2025-07-06 18:53:34 +0200
committerGitHub <noreply@github.com>2025-07-06 16:53:34 +0000
commit95a935aca05af3ccf64ecc2a6c19282dd310702f (patch)
tree03d30dac115eda7cf64de1937a1291b81102cb3b
parentba943fb77322d7d575b0f06cae2b2f66f5b5d65d (diff)
downloadgitea-95a935aca05af3ccf64ecc2a6c19282dd310702f.tar.gz
gitea-95a935aca05af3ccf64ecc2a6c19282dd310702f.zip
Enable gocritic `equalFold` and fix issues (#34952)
Continuation of https://github.com/go-gitea/gitea/pull/34678. --------- Signed-off-by: silverwind <me@silverwind.io>
-rw-r--r--.golangci.yml2
-rw-r--r--models/repo/language_stats.go9
-rw-r--r--modules/markup/mdstripper/mdstripper.go3
-rw-r--r--modules/packages/pub/metadata.go2
-rw-r--r--modules/setting/actions.go4
-rw-r--r--modules/util/slice.go3
-rw-r--r--modules/util/time_str.go2
-rw-r--r--routers/api/v1/api.go2
-rw-r--r--routers/api/v1/repo/collaborators.go2
-rw-r--r--routers/api/v1/repo/repo.go2
-rw-r--r--routers/web/repo/setting/setting.go2
-rw-r--r--services/auth/source/ldap/source_search.go2
-rw-r--r--services/context/org.go2
-rw-r--r--services/context/repo.go2
-rw-r--r--services/context/user.go2
-rw-r--r--services/repository/files/file.go2
16 files changed, 21 insertions, 22 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 70efd288ff..2ad39fbae2 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -50,6 +50,8 @@ linters:
require-explanation: true
require-specific: true
gocritic:
+ enabled-checks:
+ - equalFold
disabled-checks:
- ifElseChain
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
diff --git a/models/repo/language_stats.go b/models/repo/language_stats.go
index 0bc0f1fb40..7db8cd4dd2 100644
--- a/models/repo/language_stats.go
+++ b/models/repo/language_stats.go
@@ -157,18 +157,17 @@ func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string,
for lang, size := range stats {
if size > s {
s = size
- topLang = strings.ToLower(lang)
+ topLang = lang
}
}
for lang, size := range stats {
upd := false
- llang := strings.ToLower(lang)
for _, s := range oldstats {
// Update already existing language
- if strings.ToLower(s.Language) == llang {
+ if strings.EqualFold(s.Language, lang) {
s.CommitID = commitID
- s.IsPrimary = llang == topLang
+ s.IsPrimary = lang == topLang
s.Size = size
if _, err := sess.ID(s.ID).Cols("`commit_id`", "`size`", "`is_primary`").Update(s); err != nil {
return err
@@ -182,7 +181,7 @@ func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string,
if err := db.Insert(ctx, &LanguageStat{
RepoID: repo.ID,
CommitID: commitID,
- IsPrimary: llang == topLang,
+ IsPrimary: lang == topLang,
Language: lang,
Size: size,
}); err != nil {
diff --git a/modules/markup/mdstripper/mdstripper.go b/modules/markup/mdstripper/mdstripper.go
index 6e392444b4..5a6504416a 100644
--- a/modules/markup/mdstripper/mdstripper.go
+++ b/modules/markup/mdstripper/mdstripper.go
@@ -91,8 +91,7 @@ func (r *stripRenderer) processAutoLink(w io.Writer, link []byte) {
}
// Note: we're not attempting to match the URL scheme (http/https)
- host := strings.ToLower(u.Host)
- if host != "" && host != strings.ToLower(r.localhost.Host) {
+ if u.Host != "" && !strings.EqualFold(u.Host, r.localhost.Host) {
// Process out of band
r.links = append(r.links, linkStr)
return
diff --git a/modules/packages/pub/metadata.go b/modules/packages/pub/metadata.go
index afb464e462..9b00472eb2 100644
--- a/modules/packages/pub/metadata.go
+++ b/modules/packages/pub/metadata.go
@@ -88,7 +88,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
if err != nil {
return nil, err
}
- } else if strings.ToLower(hd.Name) == "readme.md" {
+ } else if strings.EqualFold(hd.Name, "readme.md") {
data, err := io.ReadAll(tr)
if err != nil {
return nil, err
diff --git a/modules/setting/actions.go b/modules/setting/actions.go
index 913872eaf2..8bace1f750 100644
--- a/modules/setting/actions.go
+++ b/modules/setting/actions.go
@@ -62,11 +62,11 @@ func (c logCompression) IsValid() bool {
}
func (c logCompression) IsNone() bool {
- return strings.ToLower(string(c)) == "none"
+ return string(c) == "none"
}
func (c logCompression) IsZstd() bool {
- return c == "" || strings.ToLower(string(c)) == "zstd"
+ return c == "" || string(c) == "zstd"
}
func loadActionsFrom(rootCfg ConfigProvider) error {
diff --git a/modules/util/slice.go b/modules/util/slice.go
index da6886491e..aaa729c1c9 100644
--- a/modules/util/slice.go
+++ b/modules/util/slice.go
@@ -12,8 +12,7 @@ import (
// SliceContainsString sequential searches if string exists in slice.
func SliceContainsString(slice []string, target string, insensitive ...bool) bool {
if len(insensitive) != 0 && insensitive[0] {
- target = strings.ToLower(target)
- return slices.ContainsFunc(slice, func(t string) bool { return strings.ToLower(t) == target })
+ return slices.ContainsFunc(slice, func(t string) bool { return strings.EqualFold(t, target) })
}
return slices.Contains(slice, target)
diff --git a/modules/util/time_str.go b/modules/util/time_str.go
index 0fccfe82cc..81b132c3db 100644
--- a/modules/util/time_str.go
+++ b/modules/util/time_str.go
@@ -59,7 +59,7 @@ func TimeEstimateParse(timeStr string) (int64, error) {
unit := timeStr[match[4]:match[5]]
found := false
for _, u := range timeStrGlobalVars().units {
- if strings.ToLower(unit) == u.name {
+ if strings.EqualFold(unit, u.name) {
total += amount * u.num
found = true
break
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 4a4bf12657..f412e8a06c 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -145,7 +145,7 @@ func repoAssignment() func(ctx *context.APIContext) {
)
// Check if the user is the same as the repository owner.
- if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
+ if ctx.IsSigned && strings.EqualFold(ctx.Doer.LowerName, userName) {
owner = ctx.Doer
} else {
owner, err = user_model.GetUserByName(ctx, userName)
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index c2c10cc695..eed9c19fe1 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -276,7 +276,7 @@ func GetRepoPermissions(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
collaboratorUsername := ctx.PathParam("collaborator")
- if !ctx.Doer.IsAdmin && ctx.Doer.LowerName != strings.ToLower(collaboratorUsername) && !ctx.IsUserRepoAdmin() {
+ if !ctx.Doer.IsAdmin && !strings.EqualFold(ctx.Doer.LowerName, collaboratorUsername) && !ctx.IsUserRepoAdmin() {
ctx.APIError(http.StatusForbidden, "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
return
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 8acc912796..292b267c01 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -669,7 +669,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
newRepoName = *opts.Name
}
// Check if repository name has been changed and not just a case change
- if repo.LowerName != strings.ToLower(newRepoName) {
+ if !strings.EqualFold(repo.LowerName, newRepoName) {
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
switch {
case repo_model.IsErrRepoAlreadyExist(err):
diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go
index 6e16ead183..0865d9d7c0 100644
--- a/routers/web/repo/setting/setting.go
+++ b/routers/web/repo/setting/setting.go
@@ -165,7 +165,7 @@ func handleSettingsPostUpdate(ctx *context.Context) {
newRepoName := form.RepoName
// Check if repository name has been changed.
- if repo.LowerName != strings.ToLower(newRepoName) {
+ if !strings.EqualFold(repo.LowerName, newRepoName) {
// Close the GitRepo if open
if ctx.Repo.GitRepo != nil {
ctx.Repo.GitRepo.Close()
diff --git a/services/auth/source/ldap/source_search.go b/services/auth/source/ldap/source_search.go
index e6bce04a83..f6c032492f 100644
--- a/services/auth/source/ldap/source_search.go
+++ b/services/auth/source/ldap/source_search.go
@@ -241,7 +241,7 @@ func (source *Source) listLdapGroupMemberships(l *ldap.Conn, uid string, applyGr
}
func (source *Source) getUserAttributeListedInGroup(entry *ldap.Entry) string {
- if strings.ToLower(source.UserUID) == "dn" {
+ if strings.EqualFold(source.UserUID, "dn") {
return entry.DN
}
diff --git a/services/context/org.go b/services/context/org.go
index c8b6ed09b7..1cd8923178 100644
--- a/services/context/org.go
+++ b/services/context/org.go
@@ -208,7 +208,7 @@ func OrgAssignment(opts OrgAssignmentOptions) func(ctx *Context) {
if len(teamName) > 0 {
teamExists := false
for _, team := range ctx.Org.Teams {
- if team.LowerName == strings.ToLower(teamName) {
+ if strings.EqualFold(team.LowerName, teamName) {
teamExists = true
ctx.Org.Team = team
ctx.Org.IsTeamMember = true
diff --git a/services/context/repo.go b/services/context/repo.go
index 572211712b..afc6de9b16 100644
--- a/services/context/repo.go
+++ b/services/context/repo.go
@@ -429,7 +429,7 @@ func RepoAssignment(ctx *Context) {
}
// Check if the user is the same as the repository owner
- if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
+ if ctx.IsSigned && strings.EqualFold(ctx.Doer.LowerName, userName) {
ctx.Repo.Owner = ctx.Doer
} else {
ctx.Repo.Owner, err = user_model.GetUserByName(ctx, userName)
diff --git a/services/context/user.go b/services/context/user.go
index c09ded8339..f1a3035ee9 100644
--- a/services/context/user.go
+++ b/services/context/user.go
@@ -61,7 +61,7 @@ func UserAssignmentAPI() func(ctx *APIContext) {
func userAssignment(ctx *Base, doer *user_model.User, errCb func(int, any)) (contextUser *user_model.User) {
username := ctx.PathParam("username")
- if doer != nil && doer.LowerName == strings.ToLower(username) {
+ if doer != nil && strings.EqualFold(doer.LowerName, username) {
contextUser = doer
} else {
var err error
diff --git a/services/repository/files/file.go b/services/repository/files/file.go
index 13d171d139..f48e32b427 100644
--- a/services/repository/files/file.go
+++ b/services/repository/files/file.go
@@ -144,7 +144,7 @@ func CleanGitTreePath(name string) string {
name = util.PathJoinRel(name)
// Git disallows any filenames to have a .git directory in them.
for part := range strings.SplitSeq(name, "/") {
- if strings.ToLower(part) == ".git" {
+ if strings.EqualFold(part, ".git") {
return ""
}
}