Skip to content

Commit

Permalink
refactor: remove unnecessary strings.Compare
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Nov 23, 2024
1 parent dca258a commit c1728f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ linters-settings:
section-separators:
- newLine

gocritic:
disable-all: true
enabled-checks:
# suggest removing unnecessary strings.Compare
- stringsCompare
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
Expand All @@ -75,11 +80,12 @@ linters-settings:
linters:
fast: false
enable:
- gocritic
- gofmt
- gofumpt
- goimports
- gci
disable-all: true

issues:
exclude:
5 changes: 2 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"sort"
"strings"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -64,11 +63,11 @@ func (g YamlConfig) Parse() (*Config, error) {
sort.Slice(sections, func(i, j int) bool {
sectionI, sectionJ := sections[i].Type(), sections[j].Type()

if g.Cfg.NoLexOrder || strings.Compare(sectionI, sectionJ) != 0 {
if g.Cfg.NoLexOrder || sectionI != sectionJ {
return defaultOrder[sectionI] < defaultOrder[sectionJ]
}

return strings.Compare(sections[i].String(), sections[j].String()) < 0
return sections[i].String() < sections[j].String()
})
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func (l ImportList) Len() int {
}

func (l ImportList) Less(i, j int) bool {
if strings.Compare(l[i].Path, l[j].Path) == 0 {
return strings.Compare(l[i].Name, l[j].Name) < 0
if l[i].Path == l[j].Path {
return l[i].Name < l[j].Name
}

return strings.Compare(l[i].Path, l[j].Path) < 0
return l[i].Path < l[j].Path
}

func (l ImportList) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
Expand Down

0 comments on commit c1728f0

Please sign in to comment.