1
0
mirror of https://github.com/mgechev/revive.git synced 2025-07-15 01:04:40 +02:00

Implement severity

This commit is contained in:
mgechev
2018-01-24 15:41:40 -08:00
parent b2e276ddf8
commit 4f31c1639f
8 changed files with 52 additions and 31 deletions

View File

@ -20,30 +20,32 @@ type CLIFormatter struct {
Metadata linter.FormatterMetadata
}
func formatFailure(failure linter.Failure) []string {
func formatFailure(failure linter.Failure, severity linter.Severity) []string {
fString := color.BlueString(failure.Failure)
fTypeStr := string(failure.Type)
fTypeStr := string(severity)
fType := color.RedString(fTypeStr)
lineColumn := failure.Position
pos := fmt.Sprintf("(%d, %d)", lineColumn.Start.Line, lineColumn.Start.Column)
if failure.Type == linter.FailureTypeWarning {
if severity == linter.SeverityWarning {
fType = color.YellowString(fTypeStr)
}
return []string{failure.GetFilename(), pos, fType, fString}
}
// Format formats the failures gotten from the linter.
func (f *CLIFormatter) Format(failures <-chan linter.Failure) (string, error) {
func (f *CLIFormatter) Format(failures <-chan linter.Failure, config linter.RulesConfig) (string, error) {
var result [][]string
var totalErrors = 0
var total = 0
for f := range failures {
result = append(result, formatFailure(f))
total++
if f.Type == linter.FailureTypeError {
currentType := linter.SeverityWarning
if config, ok := config[f.RuleName]; ok && config.Severity == linter.SeverityError {
currentType = linter.SeverityError
totalErrors++
}
result = append(result, formatFailure(f, linter.Severity(currentType)))
}
ps := "problems"
if total == 1 {