Skip to content

Commit c5a2a1d

Browse files
committed
Enable gocritic equalFold and autofix issues
1 parent 2c341b6 commit c5a2a1d

File tree

20 files changed

+22
-20
lines changed

20 files changed

+22
-20
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ linters:
4646
- pkg: gitea.com/go-chi/cache
4747
desc: do not use the go-chi cache package, use gitea's cache system
4848
gocritic:
49+
enabled-checks:
50+
- equalFold
4951
disabled-checks:
5052
- ifElseChain
5153
- singleCaseSwitch # Every time this occurred in the code, there was no other way.

models/repo/language_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func UpdateLanguageStats(ctx context.Context, repo *Repository, commitID string,
166166
llang := strings.ToLower(lang)
167167
for _, s := range oldstats {
168168
// Update already existing language
169-
if strings.ToLower(s.Language) == llang {
169+
if strings.EqualFold(s.Language, llang) {
170170
s.CommitID = commitID
171171
s.IsPrimary = llang == topLang
172172
s.Size = size

modules/markup/mdstripper/mdstripper.go

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

9393
// Note: we're not attempting to match the URL scheme (http/https)
9494
host := strings.ToLower(u.Host)
95-
if host != "" && host != strings.ToLower(r.localhost.Host) {
95+
if host != "" && !strings.EqualFold(host, r.localhost.Host) {
9696
// Process out of band
9797
r.links = append(r.links, linkStr)
9898
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 strings.EqualFold(string(c), "none")
6666
}
6767

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

7272
func loadActionsFrom(rootCfg ConfigProvider) error {

modules/util/slice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func SliceContainsString(slice []string, target string, insensitive ...bool) bool {
1414
if len(insensitive) != 0 && insensitive[0] {
1515
target = strings.ToLower(target)
16-
return slices.ContainsFunc(slice, func(t string) bool { return strings.ToLower(t) == target })
16+
return slices.ContainsFunc(slice, func(t string) bool { return strings.EqualFold(t, target) })
1717
}
1818

1919
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)