mirror of
https://github.com/mgechev/revive.git
synced 2025-07-15 01:04:40 +02:00
Implement severity
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user