Skip to content

Commit

Permalink
Code cleanup (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava authored Oct 23, 2021
1 parent 5d04216 commit 2c895fb
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions formatter/friendly.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (str
sev := severity(config, failure)
f.printFriendlyFailure(failure, sev)
if sev == lint.SeverityWarning {
warningMap[failure.RuleName] = warningMap[failure.RuleName] + 1
warningMap[failure.RuleName]++
totalWarnings++
}
if sev == lint.SeverityError {
errorMap[failure.RuleName] = errorMap[failure.RuleName] + 1
errorMap[failure.RuleName]++
totalErrors++
}
}
Expand Down
2 changes: 1 addition & 1 deletion rule/blank-imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
prev := file.AST.Imports[i-1]
prevPos := file.ToPosition(prev.Pos())

isSubsequentBlancInAGroup := isBlank(prev.Name) && prevPos.Line+1 == pos.Line && prev.Path.Value != embedImportPath
isSubsequentBlancInAGroup := prevPos.Line+1 == pos.Line && prev.Path.Value != embedImportPath && isBlank(prev.Name)
if isSubsequentBlancInAGroup {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion rule/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor {
w.newFailure("return in a defer function has no effect", n, 1.0, "logic", "return")
}
case *ast.CallExpr:
if isIdent(n.Fun, "recover") && !w.inADefer {
if !w.inADefer && isIdent(n.Fun, "recover") {
// confidence is not 1 because recover can be in a function that is deferred elsewhere
w.newFailure("recover must be called inside a deferred function", n, 0.8, "logic", "recover")
}
Expand Down
4 changes: 2 additions & 2 deletions rule/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (w *lintExported) lintFuncDoc(fn *ast.FuncDecl) {
// method
kind = "method"
recv := receiverType(fn)
if !ast.IsExported(recv) && !w.checkPrivateReceivers {
if !w.checkPrivateReceivers && !ast.IsExported(recv) {
// receiver is unexported
return
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
return
}
// If this GenDecl has parens and a comment, we don't check its comment form.
if gd.Lparen.IsValid() && gd.Doc != nil {
if gd.Doc != nil && gd.Lparen.IsValid() {
return
}
// The relevant text to check will be on either vs.Doc or gd.Doc.
Expand Down
2 changes: 1 addition & 1 deletion rule/imports-blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *ImportsBlacklistRule) Apply(file *lint.File, arguments lint.Arguments)
}
// we add quotes if not present, because when parsed, the value of the AST node, will be quoted
if len(argStr) > 2 && argStr[0] != '"' && argStr[len(argStr)-1] != '"' {
argStr = fmt.Sprintf(`"%s"`, argStr)
argStr = fmt.Sprintf(`%q`, argStr)
}
r.blacklist[argStr] = true
}
Expand Down
2 changes: 1 addition & 1 deletion rule/line-length-limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r lintLineLengthNum) check() {
s := bufio.NewScanner(f)
for s.Scan() {
t := s.Text()
t = strings.Replace(t, "\t", spaces, -1)
t = strings.ReplaceAll(t, "\t", spaces)
c := utf8.RuneCountInString(t)
if c > r.max {
r.onFailure(lint.Failure{
Expand Down
2 changes: 1 addition & 1 deletion rule/string-format.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (w lintStringFormatRule) parseArgument(argument interface{}, ruleNum int) (
}

// Validate scope and regex length
if len(rule[0]) == 0 {
if rule[0] == "" {
w.configError("empty scope provided", ruleNum, 0)
} else if len(rule[1]) < 2 {
w.configError("regex is too small (regexes should begin and end with '/')", ruleNum, 1)
Expand Down
4 changes: 2 additions & 2 deletions test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func assertSuccess(t *testing.T, baseDir string, fi os.FileInfo, rules []lint.Ru
return ioutil.ReadFile(baseDir + file)
})

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

ps, err := l.Lint([][]string{[]string{fi.Name()}}, rules, lint.Config{
ps, err := l.Lint([][]string{{fi.Name()}}, rules, lint.Config{
Rules: config,
})
if err != nil {
Expand Down

0 comments on commit 2c895fb

Please sign in to comment.