mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
Fix issues and add improvements
This commit is contained in:
11
config.toml
11
config.toml
@@ -1,12 +1,7 @@
|
|||||||
severity = "error"
|
severity = "warning"
|
||||||
confidence = 1.0
|
confidence = 0.8
|
||||||
|
|
||||||
[rules.else]
|
[rules.else]
|
||||||
arguments = []
|
[rules.names]
|
||||||
severity = "error"
|
|
||||||
[rules.argument-limit]
|
[rules.argument-limit]
|
||||||
arguments = ['2']
|
arguments = ['2']
|
||||||
severity = "warning"
|
|
||||||
[rules.names]
|
|
||||||
arguments = []
|
|
||||||
severity = "error"
|
|
||||||
19
main.go
19
main.go
@@ -65,6 +65,18 @@ func parseConfig(path string) *lint.Config {
|
|||||||
return 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() {
|
func main() {
|
||||||
src := `
|
src := `
|
||||||
package p
|
package p
|
||||||
@@ -86,6 +98,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
config := parseConfig("config.toml")
|
config := parseConfig("config.toml")
|
||||||
|
normalizeConfig(config)
|
||||||
lintingRules := getLintingRules(config)
|
lintingRules := getLintingRules(config)
|
||||||
|
|
||||||
failures, err := revive.Lint([]string{"foo.go", "bar.go", "baz.go"}, lintingRules, config.Rules)
|
failures, err := revive.Lint([]string{"foo.go", "bar.go", "baz.go"}, lintingRules, config.Rules)
|
||||||
@@ -108,6 +121,9 @@ func main() {
|
|||||||
|
|
||||||
exitCode := 0
|
exitCode := 0
|
||||||
for f := range failures {
|
for f := range failures {
|
||||||
|
if f.Confidence < config.Confidence {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if exitCode == 0 {
|
if exitCode == 0 {
|
||||||
exitCode = 1
|
exitCode = 1
|
||||||
}
|
}
|
||||||
@@ -116,9 +132,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
formatChan <- f
|
formatChan <- f
|
||||||
}
|
}
|
||||||
if config.Severity == lint.SeverityError && exitCode != 0 {
|
|
||||||
exitCode = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
close(formatChan)
|
close(formatChan)
|
||||||
<-exitChan
|
<-exitChan
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ func (w lintArgsNum) Visit(n ast.Node) ast.Visitor {
|
|||||||
num := int64(len(node.Type.Params.List))
|
num := int64(len(node.Type.Params.List))
|
||||||
if num > w.total {
|
if num > w.total {
|
||||||
w.onFailure(lint.Failure{
|
w.onFailure(lint.Failure{
|
||||||
|
Confidence: 1,
|
||||||
Failure: fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num),
|
Failure: fmt.Sprintf("maximum number of arguments per function exceeded; max %d but got %d", w.total, num),
|
||||||
Node: node.Type,
|
Node: node.Type,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user