Skip to content

Commit

Permalink
Drop normalize method in koanf.go, ignore case when comparing tag and…
Browse files Browse the repository at this point in the history
… a field
  • Loading branch information
anodar committed Aug 31, 2023
1 parent f11c41a commit a7e26b2
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions linter/koanf/koanf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"go/token"
"reflect"
"strings"
"unicode"

"github.com/fatih/structtag"
"golang.org/x/tools/go/analysis"
Expand Down Expand Up @@ -84,7 +83,7 @@ func checkStruct(pass *analysis.Pass, s *ast.StructType) Result {
if err != nil {
continue
}
tagName := normalize(tag.Name)
tagName := strings.ReplaceAll(tag.Name, "-", "")
fieldName := f.Names[0].Name
if !strings.EqualFold(tagName, fieldName) {
res.Errors = append(res.Errors, koanfError{
Expand All @@ -96,25 +95,6 @@ func checkStruct(pass *analysis.Pass, s *ast.StructType) Result {
return res
}

func normalize(s string) string {
ans := s[:1]
for i := 1; i < len(s); i++ {
c := rune(s[i])
if !isAlphanumeric(c) {
continue
}
if !isAlphanumeric(rune(s[i-1])) && unicode.IsLower(c) {
c = unicode.ToUpper(c)
}
ans += string(c)
}
return ans
}

func isAlphanumeric(c rune) bool {
return unicode.IsLetter(c) || unicode.IsDigit(c)
}

func main() {
singlechecker.Main(Analyzer)
}

0 comments on commit a7e26b2

Please sign in to comment.