mirror of
https://github.com/mgechev/revive.git
synced 2024-11-28 08:49:11 +02:00
44 lines
736 B
Go
44 lines
736 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/mgechev/revive/defaultrules"
|
|
"github.com/mgechev/revive/formatters"
|
|
"github.com/mgechev/revive/linter"
|
|
"github.com/mgechev/revive/rules"
|
|
)
|
|
|
|
func main() {
|
|
src := `
|
|
package p
|
|
|
|
func Test() {
|
|
if true {
|
|
return 42;
|
|
} else {
|
|
return 23;
|
|
}
|
|
}
|
|
`
|
|
|
|
linter := linter.New(func(file string) ([]byte, error) {
|
|
return []byte(src), nil
|
|
})
|
|
var result []rules.Rule
|
|
result = append(result, &defaultrules.LintElseRule{})
|
|
|
|
failures, err := linter.Lint([]string{"foo.go", "bar.go", "baz.go"}, result)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var formatter formatters.CLIFormatter
|
|
output, err := formatter.Format(failures)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println(output)
|
|
}
|