forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linters.go
57 lines (46 loc) · 1.37 KB
/
linters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package commands
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/chenfeining/golangci-lint/pkg/lint/linter"
)
func (e *Executor) initLinters() {
e.lintersCmd = &cobra.Command{
Use: "linters",
Short: "List current linters configuration",
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: e.executeLinters,
}
e.rootCmd.AddCommand(e.lintersCmd)
e.initRunConfiguration(e.lintersCmd)
}
// executeLinters runs the 'linters' CLI command, which displays the supported linters.
func (e *Executor) executeLinters(_ *cobra.Command, _ []string) error {
enabledLintersMap, err := e.EnabledLintersSet.GetEnabledLintersMap()
if err != nil {
return fmt.Errorf("can't get enabled linters: %w", err)
}
color.Green("Enabled by your configuration linters:\n")
var enabledLinters []*linter.Config
for _, lc := range enabledLintersMap {
if lc.Internal {
continue
}
enabledLinters = append(enabledLinters, lc)
}
printLinterConfigs(enabledLinters)
var disabledLCs []*linter.Config
for _, lc := range e.DBManager.GetAllSupportedLinterConfigs() {
if lc.Internal {
continue
}
if enabledLintersMap[lc.Name()] == nil {
disabledLCs = append(disabledLCs, lc)
}
}
color.Red("\nDisabled by your configuration linters:\n")
printLinterConfigs(disabledLCs)
return nil
}