2017-07-04 18:37:19 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-08-29 19:47:29 +02:00
|
|
|
"github.com/mgechev/revive/defaultrule"
|
|
|
|
"github.com/mgechev/revive/formatter"
|
2017-08-28 06:02:59 +02:00
|
|
|
"github.com/mgechev/revive/linter"
|
2017-08-29 19:47:29 +02:00
|
|
|
"github.com/mgechev/revive/rule"
|
2017-07-04 18:37:19 +02:00
|
|
|
)
|
|
|
|
|
2017-08-28 01:57:16 +02:00
|
|
|
func main() {
|
2017-07-04 18:37:19 +02:00
|
|
|
src := `
|
|
|
|
package p
|
2017-08-28 01:57:16 +02:00
|
|
|
|
|
|
|
func Test() {
|
|
|
|
if true {
|
|
|
|
return 42;
|
|
|
|
} else {
|
|
|
|
return 23;
|
|
|
|
}
|
2017-11-20 04:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func foobar(a int, b int, c int, d int) {
|
|
|
|
return a + b + c;
|
|
|
|
}
|
2017-07-04 18:37:19 +02:00
|
|
|
`
|
|
|
|
|
2017-08-28 01:57:16 +02:00
|
|
|
linter := linter.New(func(file string) ([]byte, error) {
|
|
|
|
return []byte(src), nil
|
|
|
|
})
|
2017-08-29 19:47:29 +02:00
|
|
|
var result []rule.Rule
|
2017-11-20 04:23:01 +02:00
|
|
|
result = append(result, &defaultrule.LintElseRule{}, &defaultrule.ArgumentsLimitRule{})
|
|
|
|
|
|
|
|
var config = rule.RulesConfig{
|
|
|
|
"argument-limit": []string{"3"},
|
|
|
|
}
|
2017-08-28 01:57:16 +02:00
|
|
|
|
2017-11-20 04:23:01 +02:00
|
|
|
failures, err := linter.Lint([]string{"foo.go", "bar.go", "baz.go"}, result, config)
|
2017-07-04 18:37:19 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-08-29 19:47:29 +02:00
|
|
|
var formatter formatter.CLIFormatter
|
2017-08-28 01:57:16 +02:00
|
|
|
output, err := formatter.Format(failures)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-07-04 18:37:19 +02:00
|
|
|
|
2017-08-28 01:57:16 +02:00
|
|
|
fmt.Println(output)
|
2017-07-04 18:37:19 +02:00
|
|
|
}
|