mirror of
https://github.com/mgechev/revive.git
synced 2025-02-13 13:48:36 +02:00
Add summary
This commit is contained in:
parent
87860f3d8a
commit
26911a0a0c
@ -40,16 +40,21 @@ func (f *Friendly) Name() string {
|
||||
func (f *Friendly) Format(failures <-chan lint.Failure, config lint.RulesConfig) (string, error) {
|
||||
errorMap := map[string]int{}
|
||||
warningMap := map[string]int{}
|
||||
totalErrors := 0
|
||||
totalWarnings := 0
|
||||
for failure := range failures {
|
||||
sev := severity(config, failure)
|
||||
f.printFriendlyFailure(failure, sev)
|
||||
if sev == lint.SeverityWarning {
|
||||
warningMap[failure.RuleName] = warningMap[failure.RuleName] + 1
|
||||
totalWarnings++
|
||||
}
|
||||
if sev == lint.SeverityError {
|
||||
errorMap[failure.RuleName] = errorMap[failure.RuleName] + 1
|
||||
totalErrors++
|
||||
}
|
||||
}
|
||||
f.printSummary(totalErrors, totalWarnings)
|
||||
f.printStatistics(color.RedString("Errors:"), errorMap)
|
||||
f.printStatistics(color.YellowString("Warnings:"), warningMap)
|
||||
return "", nil
|
||||
@ -79,6 +84,36 @@ type statEntry struct {
|
||||
failures int
|
||||
}
|
||||
|
||||
func (f *Friendly) printSummary(errors, warnings int) {
|
||||
emoji := warningEmoji
|
||||
if errors > 0 {
|
||||
emoji = errorEmoji
|
||||
}
|
||||
problemsLabel := "problems"
|
||||
if errors+warnings == 1 {
|
||||
problemsLabel = "problem"
|
||||
}
|
||||
warningsLabel := "warnings"
|
||||
if warnings == 1 {
|
||||
warningsLabel = "warning"
|
||||
}
|
||||
errorsLabel := "errors"
|
||||
if errors == 1 {
|
||||
errorsLabel = "error"
|
||||
}
|
||||
str := fmt.Sprintf("%d %s (%d %s, %d %s)", errors+warnings, problemsLabel, errors, errorsLabel, warnings, warningsLabel)
|
||||
if errors > 0 {
|
||||
fmt.Printf("%s %s\n", emoji, color.RedString(str))
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if warnings > 0 {
|
||||
fmt.Printf("%s %s\n", emoji, color.YellowString(str))
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Friendly) printStatistics(header string, stats map[string]int) {
|
||||
if len(stats) == 0 {
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user