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

69 lines
1.1 KiB
Go
Raw Normal View History

2017-07-04 18:37:19 +02:00
package main
import (
"fmt"
2018-01-27 06:20:49 +02:00
"io/ioutil"
2018-01-25 01:41:40 +02:00
"os"
2017-07-04 18:37:19 +02:00
2018-01-25 01:44:03 +02:00
"github.com/mgechev/revive/lint"
2017-07-04 18:37:19 +02:00
)
2018-01-28 02:22:17 +02:00
const banner = `
Welcome to:
_ __ _____ _(_)__ _____
2018-01-27 06:57:51 +02:00
| '__/ _ \ \ / / \ \ / / _ \
| | | __/\ V /| |\ V / __/
|_| \___| \_/ |_| \_/ \___|
`
2017-08-28 01:57:16 +02:00
func main() {
2018-01-28 02:22:17 +02:00
config := getConfig()
formatter := getFormatter()
files := getFiles()
2017-07-04 18:37:19 +02:00
2018-01-25 01:44:03 +02:00
revive := lint.New(func(file string) ([]byte, error) {
2018-01-28 02:22:17 +02:00
return ioutil.ReadFile(file)
2017-08-28 01:57:16 +02:00
})
2017-11-20 04:23:01 +02:00
2018-01-27 06:25:22 +02:00
lintingRules := getLintingRules(config)
2017-08-28 01:57:16 +02:00
2018-01-28 02:37:30 +02:00
failures, err := revive.Lint(files, lintingRules, *config)
2017-07-04 18:37:19 +02:00
if err != nil {
2018-02-02 20:11:40 +02:00
fail(err.Error())
2017-07-04 18:37:19 +02:00
}
2018-01-25 01:44:03 +02:00
formatChan := make(chan lint.Failure)
2018-01-25 01:41:40 +02:00
exitChan := make(chan bool)
2017-07-04 18:37:19 +02:00
2018-01-27 06:25:22 +02:00
var output string
2018-01-25 01:41:40 +02:00
go (func() {
2018-01-27 06:20:49 +02:00
output, err = formatter.Format(formatChan, config.Rules)
2018-01-25 01:41:40 +02:00
if err != nil {
2018-02-02 20:11:40 +02:00
fail(err.Error())
2018-01-25 01:41:40 +02:00
}
exitChan <- true
})()
exitCode := 0
for f := range failures {
2018-01-27 06:34:20 +02:00
if f.Confidence < config.Confidence {
continue
}
2018-01-25 01:46:43 +02:00
if exitCode == 0 {
2018-01-25 01:41:40 +02:00
exitCode = 1
}
2018-01-27 06:20:49 +02:00
if c, ok := config.Rules[f.RuleName]; ok && c.Severity == lint.SeverityError {
2018-01-25 01:46:43 +02:00
exitCode = 2
}
2018-01-25 01:41:40 +02:00
formatChan <- f
}
2018-01-27 06:25:22 +02:00
2018-01-25 01:41:40 +02:00
close(formatChan)
<-exitChan
2018-01-28 09:03:07 +02:00
if output != "" {
fmt.Println(output)
}
2018-01-25 01:41:40 +02:00
os.Exit(exitCode)
2017-07-04 18:37:19 +02:00
}