1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00

Fix issues and add improvements

This commit is contained in:
mgechev 2018-01-26 20:34:20 -08:00
parent 3540aca153
commit 466e9339e4
3 changed files with 22 additions and 13 deletions

View File

@ -1,12 +1,7 @@
severity = "error"
confidence = 1.0
severity = "warning"
confidence = 0.8
[rules.else]
arguments = []
severity = "error"
[rules.names]
[rules.argument-limit]
arguments = ['2']
severity = "warning"
[rules.names]
arguments = []
severity = "error"

19
main.go
View File

@ -65,6 +65,18 @@ func parseConfig(path string) *lint.Config {
return config
}
func normalizeConfig(config *lint.Config) {
severity := config.Severity
if severity != "" {
for k, v := range config.Rules {
if v.Severity == "" {
v.Severity = severity
}
config.Rules[k] = v
}
}
}
func main() {
src := `
package p
@ -86,6 +98,7 @@ func main() {
})
config := parseConfig("config.toml")
normalizeConfig(config)
lintingRules := getLintingRules(config)
failures, err := revive.Lint([]string{"foo.go", "bar.go", "baz.go"}, lintingRules, config.Rules)
@ -108,6 +121,9 @@ func main() {
exitCode := 0
for f := range failures {
if f.Confidence < config.Confidence {
continue
}
if exitCode == 0 {
exitCode = 1
}
@ -116,9 +132,6 @@ func main() {
}
formatChan <- f
}
if config.Severity == lint.SeverityError && exitCode != 0 {
exitCode = 2
}
close(formatChan)
<-exitChan

View File

@ -51,8 +51,9 @@ func (w lintArgsNum) Visit(n ast.Node) ast.Visitor {
num := int64(len(node.Type.Params.List))
if num > w.total {
w.onFailure(lint.Failure{
Failure: fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num),
Node: node.Type,
Confidence: 1,
Failure: fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num),
Node: node.Type,
})
return w
}