|
1 | 1 | package commands |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
| 4 | + "log" |
5 | 5 | "os" |
6 | | - "strings" |
7 | 6 |
|
8 | 7 | "github.com/fatih/color" |
9 | 8 | "github.com/golangci/golangci-lint/pkg/lint/linter" |
10 | 9 | "github.com/golangci/golangci-lint/pkg/lint/lintersdb" |
11 | | - "github.com/golangci/golangci-lint/pkg/logutils" |
12 | 10 | "github.com/spf13/cobra" |
13 | 11 | ) |
14 | 12 |
|
15 | 13 | func (e *Executor) initLinters() { |
16 | | - var lintersCmd = &cobra.Command{ |
| 14 | + lintersCmd := &cobra.Command{ |
17 | 15 | Use: "linters", |
18 | | - Short: "List linters", |
| 16 | + Short: "List current linters configuration", |
19 | 17 | Run: e.executeLinters, |
20 | 18 | } |
21 | 19 | e.rootCmd.AddCommand(lintersCmd) |
| 20 | + e.initRunConfiguration(lintersCmd) |
22 | 21 | } |
23 | 22 |
|
24 | | -func printLinterConfigs(lcs []linter.Config) { |
25 | | - for _, lc := range lcs { |
26 | | - fmt.Fprintf(logutils.StdOut, "%s: %s [fast: %t]\n", color.YellowString(lc.Linter.Name()), |
27 | | - lc.Linter.Desc(), !lc.DoesFullImport) |
| 23 | +func IsLinterInConfigsList(name string, linters []linter.Config) bool { |
| 24 | + for _, linter := range linters { |
| 25 | + if linter.Linter.Name() == name { |
| 26 | + return true |
| 27 | + } |
28 | 28 | } |
| 29 | + |
| 30 | + return false |
29 | 31 | } |
30 | 32 |
|
31 | 33 | func (e Executor) executeLinters(cmd *cobra.Command, args []string) { |
32 | | - var enabledLCs, disabledLCs []linter.Config |
33 | | - for _, lc := range lintersdb.GetAllSupportedLinterConfigs() { |
34 | | - if lc.EnabledByDefault { |
35 | | - enabledLCs = append(enabledLCs, lc) |
36 | | - } else { |
37 | | - disabledLCs = append(disabledLCs, lc) |
38 | | - } |
| 34 | + enabledLCs, err := lintersdb.GetEnabledLinters(e.cfg, e.log.Child("lintersdb")) |
| 35 | + if err != nil { |
| 36 | + log.Fatalf("Can't get enabled linters: %s", err) |
39 | 37 | } |
40 | 38 |
|
41 | | - color.Green("Enabled by default linters:\n") |
| 39 | + color.Green("Enabled by your configuration linters:\n") |
42 | 40 | printLinterConfigs(enabledLCs) |
43 | | - color.Red("\nDisabled by default linters:\n") |
44 | | - printLinterConfigs(disabledLCs) |
45 | 41 |
|
46 | | - color.Green("\nLinters presets:") |
47 | | - for _, p := range lintersdb.AllPresets() { |
48 | | - linters := lintersdb.GetAllLinterConfigsForPreset(p) |
49 | | - linterNames := []string{} |
50 | | - for _, lc := range linters { |
51 | | - linterNames = append(linterNames, lc.Linter.Name()) |
| 42 | + var disabledLCs []linter.Config |
| 43 | + for _, lc := range lintersdb.GetAllSupportedLinterConfigs() { |
| 44 | + if !IsLinterInConfigsList(lc.Linter.Name(), enabledLCs) { |
| 45 | + disabledLCs = append(disabledLCs, lc) |
52 | 46 | } |
53 | | - fmt.Fprintf(logutils.StdOut, "%s: %s\n", color.YellowString(p), strings.Join(linterNames, ", ")) |
54 | 47 | } |
55 | 48 |
|
| 49 | + color.Red("\nDisabled by your configuration linters:\n") |
| 50 | + printLinterConfigs(disabledLCs) |
| 51 | + |
56 | 52 | os.Exit(0) |
57 | 53 | } |
0 commit comments