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

46 lines
808 B
Go
Raw Normal View History

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;
2017-09-02 06:46:54 +02:00
// revive:disable no-else-return
2017-08-28 01:57:16 +02:00
} else {
return 23;
}
2017-09-02 06:46:54 +02:00
// revive:enable no-else-return
2017-08-28 01:57:16 +02:00
}
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
result = append(result, &defaultrule.LintElseRule{})
2017-08-28 01:57:16 +02:00
failures, err := linter.Lint([]string{"foo.go" /*, "bar.go", "baz.go"*/}, result)
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
}