mirror of
https://github.com/mgechev/revive.git
synced 2025-07-17 01:12:27 +02:00
Code cleanup (#606)
This commit is contained in:
@ -49,11 +49,11 @@ func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (str
|
|||||||
sev := severity(config, failure)
|
sev := severity(config, failure)
|
||||||
f.printFriendlyFailure(failure, sev)
|
f.printFriendlyFailure(failure, sev)
|
||||||
if sev == lint.SeverityWarning {
|
if sev == lint.SeverityWarning {
|
||||||
warningMap[failure.RuleName] = warningMap[failure.RuleName] + 1
|
warningMap[failure.RuleName]++
|
||||||
totalWarnings++
|
totalWarnings++
|
||||||
}
|
}
|
||||||
if sev == lint.SeverityError {
|
if sev == lint.SeverityError {
|
||||||
errorMap[failure.RuleName] = errorMap[failure.RuleName] + 1
|
errorMap[failure.RuleName]++
|
||||||
totalErrors++
|
totalErrors++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failu
|
|||||||
prev := file.AST.Imports[i-1]
|
prev := file.AST.Imports[i-1]
|
||||||
prevPos := file.ToPosition(prev.Pos())
|
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 {
|
if isSubsequentBlancInAGroup {
|
||||||
continue
|
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")
|
w.newFailure("return in a defer function has no effect", n, 1.0, "logic", "return")
|
||||||
}
|
}
|
||||||
case *ast.CallExpr:
|
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
|
// 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")
|
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
|
// method
|
||||||
kind = "method"
|
kind = "method"
|
||||||
recv := receiverType(fn)
|
recv := receiverType(fn)
|
||||||
if !ast.IsExported(recv) && !w.checkPrivateReceivers {
|
if !w.checkPrivateReceivers && !ast.IsExported(recv) {
|
||||||
// receiver is unexported
|
// receiver is unexported
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ func (w *lintExported) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genD
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If this GenDecl has parens and a comment, we don't check its comment form.
|
// 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
|
return
|
||||||
}
|
}
|
||||||
// The relevant text to check will be on either vs.Doc or gd.Doc.
|
// 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
|
// 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] != '"' {
|
if len(argStr) > 2 && argStr[0] != '"' && argStr[len(argStr)-1] != '"' {
|
||||||
argStr = fmt.Sprintf(`"%s"`, argStr)
|
argStr = fmt.Sprintf(`%q`, argStr)
|
||||||
}
|
}
|
||||||
r.blacklist[argStr] = true
|
r.blacklist[argStr] = true
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func (r lintLineLengthNum) check() {
|
|||||||
s := bufio.NewScanner(f)
|
s := bufio.NewScanner(f)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
t := s.Text()
|
t := s.Text()
|
||||||
t = strings.Replace(t, "\t", spaces, -1)
|
t = strings.ReplaceAll(t, "\t", spaces)
|
||||||
c := utf8.RuneCountInString(t)
|
c := utf8.RuneCountInString(t)
|
||||||
if c > r.max {
|
if c > r.max {
|
||||||
r.onFailure(lint.Failure{
|
r.onFailure(lint.Failure{
|
||||||
|
@ -119,7 +119,7 @@ func (w lintStringFormatRule) parseArgument(argument interface{}, ruleNum int) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate scope and regex length
|
// Validate scope and regex length
|
||||||
if len(rule[0]) == 0 {
|
if rule[0] == "" {
|
||||||
w.configError("empty scope provided", ruleNum, 0)
|
w.configError("empty scope provided", ruleNum, 0)
|
||||||
} else if len(rule[1]) < 2 {
|
} else if len(rule[1]) < 2 {
|
||||||
w.configError("regex is too small (regexes should begin and end with '/')", ruleNum, 1)
|
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)
|
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,
|
Rules: config,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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())
|
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,
|
Rules: config,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user