Skip to content

Commit 2c895fb

Browse files
authored
Code cleanup (#606)
1 parent 5d04216 commit 2c895fb

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

formatter/friendly.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (str
4949
sev := severity(config, failure)
5050
f.printFriendlyFailure(failure, sev)
5151
if sev == lint.SeverityWarning {
52-
warningMap[failure.RuleName] = warningMap[failure.RuleName] + 1
52+
warningMap[failure.RuleName]++
5353
totalWarnings++
5454
}
5555
if sev == lint.SeverityError {
56-
errorMap[failure.RuleName] = errorMap[failure.RuleName] + 1
56+
errorMap[failure.RuleName]++
5757
totalErrors++
5858
}
5959
}

rule/blank-imports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
4343
prev := file.AST.Imports[i-1]
4444
prevPos := file.ToPosition(prev.Pos())
4545

46-
isSubsequentBlancInAGroup := isBlank(prev.Name) && prevPos.Line+1 == pos.Line && prev.Path.Value != embedImportPath
46+
isSubsequentBlancInAGroup := prevPos.Line+1 == pos.Line && prev.Path.Value != embedImportPath && isBlank(prev.Name)
4747
if isSubsequentBlancInAGroup {
4848
continue
4949
}

rule/defer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor {
8888
w.newFailure("return in a defer function has no effect", n, 1.0, "logic", "return")
8989
}
9090
case *ast.CallExpr:
91-
if isIdent(n.Fun, "recover") && !w.inADefer {
91+
if !w.inADefer && isIdent(n.Fun, "recover") {
9292
// confidence is not 1 because recover can be in a function that is deferred elsewhere
9393
w.newFailure("recover must be called inside a deferred function", n, 0.8, "logic", "recover")
9494
}

rule/exported.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) {
109109
// method
110110
kind = "method"
111111
recv := receiverType(fn)
112-
if !ast.IsExported(recv) && !w.checkPrivateReceivers {
112+
if !w.checkPrivateReceivers && !ast.IsExported(recv) {
113113
// receiver is unexported
114114
return
115115
}
@@ -259,7 +259,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
259259
return
260260
}
261261
// If this GenDecl has parens and a comment, we don't check its comment form.
262-
if gd.Lparen.IsValid() && gd.Doc != nil {
262+
if gd.Doc != nil && gd.Lparen.IsValid() {
263263
return
264264
}
265265
// The relevant text to check will be on either vs.Doc or gd.Doc.

rule/imports-blacklist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments)
2929
}
3030
// we add quotes if not present, because when parsed, the value of the AST node, will be quoted
3131
if len(argStr) > 2 && argStr[0] != '"' && argStr[len(argStr)-1] != '"' {
32-
argStr = fmt.Sprintf(`"%s"`, argStr)
32+
argStr = fmt.Sprintf(`%q`, argStr)
3333
}
3434
r.blacklist[argStr] = true
3535
}

rule/line-length-limit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (r lintLineLengthNum) check() {
6161
s := bufio.NewScanner(f)
6262
for s.Scan() {
6363
t := s.Text()
64-
t = strings.Replace(t, "\t", spaces, -1)
64+
t = strings.ReplaceAll(t, "\t", spaces)
6565
c := utf8.RuneCountInString(t)
6666
if c > r.max {
6767
r.onFailure(lint.Failure{

rule/string-format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (w lintStringFormatRule) parseArgument(argument interface{}, ruleNum int) (
119119
}
120120

121121
// Validate scope and regex length
122-
if len(rule[0]) == 0 {
122+
if rule[0] == "" {
123123
w.configError("empty scope provided", ruleNum, 0)
124124
} else if len(rule[1]) < 2 {
125125
w.configError("regex is too small (regexes should begin and end with '/')", ruleNum, 1)

test/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func assertSuccess(t *testing.T, baseDir string, fi os.FileInfo, rules []lint.Ru
4646
return ioutil.ReadFile(baseDir + file)
4747
})
4848

49-
ps, err := l.Lint([][]string{[]string{fi.Name()}}, rules, lint.Config{
49+
ps, err := l.Lint([][]string{{fi.Name()}}, rules, lint.Config{
5050
Rules: config,
5151
})
5252
if err != nil {
@@ -73,7 +73,7 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru
7373
return errors.Errorf("Test file %v does not have instructions", fi.Name())
7474
}
7575

76-
ps, err := l.Lint([][]string{[]string{fi.Name()}}, rules, lint.Config{
76+
ps, err := l.Lint([][]string{{fi.Name()}}, rules, lint.Config{
7777
Rules: config,
7878
})
7979
if err != nil {

0 commit comments

Comments
 (0)