mirror of
https://github.com/mgechev/revive.git
synced 2025-02-03 13:11:25 +02:00
Code cleanup (#606)
This commit is contained in:
parent
5d04216294
commit
2c895fb33f
@ -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++
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user