Skip to content

Commit edd0baa

Browse files
committed
enable gocritic lint
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 53d8355 commit edd0baa

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ linters:
33
- unused
44
enable:
55
- gci
6+
- gocritic
67
- gofumpt
78
- govet
89
- misspell

templates/cc/register.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (fns CCFuncs) failUnimplemented(message string) string {
436436
}
437437

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

442442
func (fns CCFuncs) output(file pgs.File, ext string) string {

templates/goshared/register.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ func (fns goSharedFuncs) errIdxCause(ctx shared.RuleContext, idx, cause string,
114114
n := fns.Name(f)
115115

116116
var fld string
117-
if idx != "" {
117+
switch {
118+
case idx != "":
118119
fld = fmt.Sprintf(`fmt.Sprintf("%s[%%v]", %s)`, n, idx)
119-
} else if ctx.Index != "" {
120+
case ctx.Index != "":
120121
fld = fmt.Sprintf(`fmt.Sprintf("%s[%%v]", %s)`, n, ctx.Index)
121-
} else {
122+
default:
122123
fld = fmt.Sprintf("%q", n)
123124
}
124125

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

396397
if collision, ok := nameCollision[pkgName]; ok {
397398
nameCollision[pkgName] = collision + 1
398-
pkgName = pkgName + pgs.Name(strconv.Itoa(nameCollision[pkgName]))
399+
pkgName += pgs.Name(strconv.Itoa(nameCollision[pkgName]))
399400
} else {
400401
nameCollision[pkgName] = 0
401402
}

templates/java/register.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ func JavaFilePath(f pgs.File, ctx pgsgo.Context, tpl *template.Template) *pgs.Fi
124124
return nil
125125
}
126126

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

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

@@ -442,10 +442,10 @@ func (fns javaFuncs) javaTypeLiteralSuffixForPrototype(t pgs.ProtoType) string {
442442
func (fns javaFuncs) javaStringEscape(s string) string {
443443
s = fmt.Sprintf("%q", s)
444444
s = s[1 : len(s)-1]
445-
s = strings.Replace(s, `\u00`, `\x`, -1)
446-
s = strings.Replace(s, `\x`, `\\x`, -1)
447-
// s = strings.Replace(s, `\`, `\\`, -1)
448-
s = strings.Replace(s, `"`, `\"`, -1)
445+
s = strings.ReplaceAll(s, `\u00`, `\x`)
446+
s = strings.ReplaceAll(s, `\x`, `\\x`)
447+
// s = strings.ReplaceAll(s, `\`, `\\`)
448+
s = strings.ReplaceAll(s, `"`, `\"`)
449449
return `"` + s + `"`
450450
}
451451

0 commit comments

Comments
 (0)