Skip to content

Commit 95a935a

Browse files
authored
Enable gocritic equalFold and fix issues (#34952)
Continuation of #34678. --------- Signed-off-by: silverwind <[email protected]>
1 parent ba943fb commit 95a935a

File tree

16 files changed

+21
-22
lines changed

16 files changed

+21
-22
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ linters:
5050
require-explanation: true
5151
require-specific: true
5252
gocritic:
53+
enabled-checks:
54+
- equalFold
5355
disabled-checks:
5456
- ifElseChain
5557
- singleCaseSwitch # Every time this occurred in the code, there was no other way.

models/repo/language_stats.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,17 @@ func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string,
157157
for lang, size := range stats {
158158
if size > s {
159159
s = size
160-
topLang = strings.ToLower(lang)
160+
topLang = lang
161161
}
162162
}
163163

164164
for lang, size := range stats {
165165
upd := false
166-
llang := strings.ToLower(lang)
167166
for _, s := range oldstats {
168167
// Update already existing language
169-
if strings.ToLower(s.Language) == llang {
168+
if strings.EqualFold(s.Language, lang) {
170169
s.CommitID = commitID
171-
s.IsPrimary = llang == topLang
170+
s.IsPrimary = lang == topLang
172171
s.Size = size
173172
if _, err := sess.ID(s.ID).Cols("`commit_id`", "`size`", "`is_primary`").Update(s); err != nil {
174173
return err
@@ -182,7 +181,7 @@ func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string,
182181
if err := db.Insert(ctx, &LanguageStat{
183182
RepoID: repo.ID,
184183
CommitID: commitID,
185-
IsPrimary: llang == topLang,
184+
IsPrimary: lang == topLang,
186185
Language: lang,
187186
Size: size,
188187
}); err != nil {

modules/markup/mdstripper/mdstripper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ func (r *stripRenderer) processAutoLink(w io.Writer, link []byte) {
9191
}
9292

9393
// Note: we're not attempting to match the URL scheme (http/https)
94-
host := strings.ToLower(u.Host)
95-
if host != "" && host != strings.ToLower(r.localhost.Host) {
94+
if u.Host != "" && !strings.EqualFold(u.Host, r.localhost.Host) {
9695
// Process out of band
9796
r.links = append(r.links, linkStr)
9897
return

modules/packages/pub/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
8888
if err != nil {
8989
return nil, err
9090
}
91-
} else if strings.ToLower(hd.Name) == "readme.md" {
91+
} else if strings.EqualFold(hd.Name, "readme.md") {
9292
data, err := io.ReadAll(tr)
9393
if err != nil {
9494
return nil, err

modules/setting/actions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ func (c logCompression) IsValid() bool {
6262
}
6363

6464
func (c logCompression) IsNone() bool {
65-
return strings.ToLower(string(c)) == "none"
65+
return string(c) == "none"
6666
}
6767

6868
func (c logCompression) IsZstd() bool {
69-
return c == "" || strings.ToLower(string(c)) == "zstd"
69+
return c == "" || string(c) == "zstd"
7070
}
7171

7272
func loadActionsFrom(rootCfg ConfigProvider) error {

modules/util/slice.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212
// SliceContainsString sequential searches if string exists in slice.
1313
func SliceContainsString(slice []string, target string, insensitive ...bool) bool {
1414
if len(insensitive) != 0 && insensitive[0] {
15-
target = strings.ToLower(target)
16-
return slices.ContainsFunc(slice, func(t string) bool { return strings.ToLower(t) == target })
15+
return slices.ContainsFunc(slice, func(t string) bool { return strings.EqualFold(t, target) })
1716
}
1817

1918
return slices.Contains(slice, target)

modules/util/time_str.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TimeEstimateParse(timeStr string) (int64, error) {
5959
unit := timeStr[match[4]:match[5]]
6060
found := false
6161
for _, u := range timeStrGlobalVars().units {
62-
if strings.ToLower(unit) == u.name {
62+
if strings.EqualFold(unit, u.name) {
6363
total += amount * u.num
6464
found = true
6565
break

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func repoAssignment() func(ctx *context.APIContext) {
145145
)
146146

147147
// Check if the user is the same as the repository owner.
148-
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
148+
if ctx.IsSigned && strings.EqualFold(ctx.Doer.LowerName, userName) {
149149
owner = ctx.Doer
150150
} else {
151151
owner, err = user_model.GetUserByName(ctx, userName)

routers/api/v1/repo/collaborators.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func GetRepoPermissions(ctx *context.APIContext) {
276276
// "$ref": "#/responses/forbidden"
277277

278278
collaboratorUsername := ctx.PathParam("collaborator")
279-
if !ctx.Doer.IsAdmin && ctx.Doer.LowerName != strings.ToLower(collaboratorUsername) && !ctx.IsUserRepoAdmin() {
279+
if !ctx.Doer.IsAdmin && !strings.EqualFold(ctx.Doer.LowerName, collaboratorUsername) && !ctx.IsUserRepoAdmin() {
280280
ctx.APIError(http.StatusForbidden, "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
281281
return
282282
}

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
669669
newRepoName = *opts.Name
670670
}
671671
// Check if repository name has been changed and not just a case change
672-
if repo.LowerName != strings.ToLower(newRepoName) {
672+
if !strings.EqualFold(repo.LowerName, newRepoName) {
673673
if err := repo_service.ChangeRepositoryName(ctx, ctx.Doer, repo, newRepoName); err != nil {
674674
switch {
675675
case repo_model.IsErrRepoAlreadyExist(err):

0 commit comments

Comments
 (0)