Skip to content

Enable gocritic linter #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
- unused
enable:
- gci
- gocritic
- gofumpt
- govet
- misspell
Expand Down
2 changes: 1 addition & 1 deletion templates/cc/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (fns CCFuncs) failUnimplemented(message string) string {
}

func (fns CCFuncs) staticVarName(msg pgs.Message) string {
return "validator_" + strings.Replace(fns.className(msg), ":", "_", -1)
return "validator_" + strings.ReplaceAll(fns.className(msg), ":", "_")
}

func (fns CCFuncs) output(file pgs.File, ext string) string {
Expand Down
9 changes: 5 additions & 4 deletions templates/goshared/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func (fns goSharedFuncs) errIdxCause(ctx shared.RuleContext, idx, cause string,
n := fns.Name(f)

var fld string
if idx != "" {
switch {
case idx != "":
fld = fmt.Sprintf(`fmt.Sprintf("%s[%%v]", %s)`, n, idx)
} else if ctx.Index != "" {
case ctx.Index != "":
fld = fmt.Sprintf(`fmt.Sprintf("%s[%%v]", %s)`, n, ctx.Index)
} else {
default:
fld = fmt.Sprintf("%q", n)
}

Expand Down Expand Up @@ -395,7 +396,7 @@ func (fns goSharedFuncs) enumPackages(enums []pgs.Enum) map[pgs.Name]NormalizedE

if collision, ok := nameCollision[pkgName]; ok {
nameCollision[pkgName] = collision + 1
pkgName = pkgName + pgs.Name(strconv.Itoa(nameCollision[pkgName]))
pkgName += pgs.Name(strconv.Itoa(nameCollision[pkgName]))
} else {
nameCollision[pkgName] = 0
}
Expand Down
16 changes: 8 additions & 8 deletions templates/java/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ func JavaFilePath(f pgs.File, ctx pgsgo.Context, tpl *template.Template) *pgs.Fi
return nil
}

fullPath := strings.Replace(javaPackage(f), ".", string(os.PathSeparator), -1)
fullPath := strings.ReplaceAll(javaPackage(f), ".", string(os.PathSeparator))
fileName := classNameFile(f) + "Validator.java"
filePath := pgs.JoinPaths(fullPath, fileName)
return &filePath
}

func JavaMultiFilePath(f pgs.File, m pgs.Message) pgs.FilePath {
fullPath := strings.Replace(javaPackage(f), ".", string(os.PathSeparator), -1)
fullPath := strings.ReplaceAll(javaPackage(f), ".", string(os.PathSeparator))
fileName := classNameMessage(m) + "Validator.java"
filePath := pgs.JoinPaths(fullPath, fileName)
return filePath
Expand Down Expand Up @@ -167,9 +167,9 @@ func classNameMessage(m pgs.Message) string {
// When multiple files is false, underscores are stripped. Short of rewriting all the name sanitization
// logic for java, using "UnderscoreUnderscoreUnderscore" is an escape sequence seems to work with an extremely
// small likelihood of name conflict.
className = strings.Replace(className, "_", "UnderscoreUnderscoreUnderscore", -1)
className = strings.ReplaceAll(className, "_", "UnderscoreUnderscoreUnderscore")
className = sanitizeClassName(className)
className = strings.Replace(className, "UnderscoreUnderscoreUnderscore", "_", -1)
className = strings.ReplaceAll(className, "UnderscoreUnderscoreUnderscore", "_")
return className
}

Expand Down Expand Up @@ -442,10 +442,10 @@ func (fns javaFuncs) javaTypeLiteralSuffixForPrototype(t pgs.ProtoType) string {
func (fns javaFuncs) javaStringEscape(s string) string {
s = fmt.Sprintf("%q", s)
s = s[1 : len(s)-1]
s = strings.Replace(s, `\u00`, `\x`, -1)
s = strings.Replace(s, `\x`, `\\x`, -1)
// s = strings.Replace(s, `\`, `\\`, -1)
s = strings.Replace(s, `"`, `\"`, -1)
s = strings.ReplaceAll(s, `\u00`, `\x`)
s = strings.ReplaceAll(s, `\x`, `\\x`)
// s = strings.ReplaceAll(s, `\`, `\\`)
s = strings.ReplaceAll(s, `"`, `\"`)
return `"` + s + `"`
}

Expand Down