mirror of
https://github.com/mgechev/revive.git
synced 2025-07-17 01:12:27 +02:00
Implement severity
This commit is contained in:
38
main.go
38
main.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mgechev/revive/formatter"
|
||||
"github.com/mgechev/revive/linter"
|
||||
@ -20,7 +21,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func foobar(a int, b int, c int, d int) {
|
||||
func foo_bar(a int, b int, c int, d int) {
|
||||
return a + b + c;
|
||||
}
|
||||
`
|
||||
@ -29,10 +30,13 @@ func main() {
|
||||
return []byte(src), nil
|
||||
})
|
||||
var result []linter.Rule
|
||||
result = append(result, &rule.LintElseRule{}, &rule.ArgumentsLimitRule{})
|
||||
result = append(result, &rule.LintElseRule{}, &rule.ArgumentsLimitRule{}, &rule.NamesRule{})
|
||||
|
||||
var config = linter.RulesConfig{
|
||||
"argument-limit": []string{"3"},
|
||||
"argument-limit": linter.RuleConfig{
|
||||
Arguments: []string{"3"},
|
||||
Severity: linter.SeverityWarning,
|
||||
},
|
||||
}
|
||||
|
||||
failures, err := revive.Lint([]string{"foo.go", "bar.go", "baz.go"}, result, config)
|
||||
@ -40,11 +44,29 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var formatter formatter.CLIFormatter
|
||||
output, err := formatter.Format(failures)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
formatChan := make(chan linter.Failure)
|
||||
exitChan := make(chan bool)
|
||||
var output string
|
||||
|
||||
go (func() {
|
||||
var formatter formatter.CLIFormatter
|
||||
output, err = formatter.Format(formatChan, config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
exitChan <- true
|
||||
})()
|
||||
|
||||
exitCode := 0
|
||||
for f := range failures {
|
||||
if c, ok := config[f.RuleName]; ok && c.Severity == linter.SeverityError {
|
||||
exitCode = 1
|
||||
}
|
||||
formatChan <- f
|
||||
}
|
||||
close(formatChan)
|
||||
<-exitChan
|
||||
fmt.Println(output)
|
||||
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
Reference in New Issue
Block a user