@@ -8,12 +8,14 @@ import (
8
8
"log"
9
9
"os"
10
10
"runtime"
11
+ "sort"
11
12
"strings"
12
13
"time"
13
14
14
15
"github.com/fatih/color"
15
16
"github.com/spf13/cobra"
16
17
"github.com/spf13/pflag"
18
+ "golang.org/x/exp/maps"
17
19
18
20
"github.com/golangci/golangci-lint/pkg/config"
19
21
"github.com/golangci/golangci-lint/pkg/exitcodes"
@@ -125,7 +127,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
125
127
const allowSerialDesc = "Allow multiple golangci-lint instances running, but serialize them around a lock. " +
126
128
"If false (default) - golangci-lint exits with an error if it fails to acquire file lock on start."
127
129
fs .BoolVar (& rc .AllowSerialRunners , "allow-serial-runners" , false , wh (allowSerialDesc ))
128
- fs .BoolVar (& rc .ShowStatsPerLinter , "show-stats-per-linter " , false , wh ("Show stats per linter" ))
130
+ fs .BoolVar (& rc .ShowStats , "show-stats" , false , wh ("Show statistics per linter" ))
129
131
130
132
// Linters settings config
131
133
lsc := & cfg .LintersSettings
@@ -493,18 +495,27 @@ func (e *Executor) createPrinter(format string, w io.Writer) (printers.Printer,
493
495
}
494
496
495
497
func (e * Executor ) printStats (issues []result.Issue ) {
496
- if e .cfg .Run .ShowStatsPerLinter {
497
- stats := map [string ]int {}
498
- for idx := range issues {
499
- stats [issues [idx ].FromLinter ]++
500
- }
501
- e .runCmd .Println ("Stats per linter:" )
502
- for linter , count := range stats {
503
- e .runCmd .Printf (" %s: %d\n " , linter , count )
504
- }
505
- if len (stats ) == 0 {
506
- e .runCmd .Println (" no issues" )
507
- }
498
+ if ! e .cfg .Run .ShowStats {
499
+ return
500
+ }
501
+
502
+ if len (issues ) == 0 {
503
+ e .runCmd .Println ("0 report" )
504
+ return
505
+ }
506
+
507
+ stats := map [string ]int {}
508
+ for idx := range issues {
509
+ stats [issues [idx ].FromLinter ]++
510
+ }
511
+
512
+ e .runCmd .Printf ("%d reports:\n " , len (issues ))
513
+
514
+ keys := maps .Keys (stats )
515
+ sort .Strings (keys )
516
+
517
+ for _ , key := range keys {
518
+ e .runCmd .Printf ("* %s: %d\n " , key , stats [key ])
508
519
}
509
520
}
510
521
0 commit comments