11package commands
22
33import (
4+ "encoding/json"
45 "fmt"
56
67 "github.com/fatih/color"
@@ -14,8 +15,14 @@ import (
1415 "github.com/golangci/golangci-lint/pkg/logutils"
1516)
1617
18+ type lintersHelp struct {
19+ Enabled []linterHelp
20+ Disabled []linterHelp
21+ }
22+
1723type lintersOptions struct {
1824 config.LoaderOptions
25+ JSON bool
1926}
2027
2128type lintersCommand struct {
@@ -54,6 +61,8 @@ func newLintersCommand(logger logutils.Log) *lintersCommand {
5461 setupConfigFileFlagSet (fs , & c .opts .LoaderOptions )
5562 setupLintersFlagSet (c .viper , fs )
5663
64+ fs .BoolVar (& c .opts .JSON , "json" , false , color .GreenString ("Display as JSON" ))
65+
5766 c .cmd = lintersCmd
5867
5968 return c
@@ -85,7 +94,7 @@ func (c *lintersCommand) execute(_ *cobra.Command, _ []string) error {
8594 }
8695
8796 var enabledLinters []* linter.Config
88- var disabledLCs []* linter.Config
97+ var disabledLinters []* linter.Config
8998
9099 for _ , lc := range c .dbManager .GetAllSupportedLinterConfigs () {
91100 if lc .Internal {
@@ -97,16 +106,31 @@ func (c *lintersCommand) execute(_ *cobra.Command, _ []string) error {
97106 }
98107
99108 if enabledLintersMap [lc .Name ()] == nil {
100- disabledLCs = append (disabledLCs , lc )
109+ disabledLinters = append (disabledLinters , lc )
101110 } else {
102111 enabledLinters = append (enabledLinters , lc )
103112 }
104113 }
105114
115+ if c .opts .JSON {
116+ formatters := lintersHelp {}
117+
118+ for _ , lc := range enabledLinters {
119+ formatters .Enabled = append (formatters .Enabled , newLinterHelp (lc ))
120+ }
121+
122+ for _ , lc := range disabledLinters {
123+ formatters .Disabled = append (formatters .Disabled , newLinterHelp (lc ))
124+ }
125+
126+ return json .NewEncoder (c .cmd .OutOrStdout ()).Encode (formatters )
127+ }
128+
106129 color .Green ("Enabled by your configuration linters:\n " )
107130 printLinters (enabledLinters )
131+
108132 color .Red ("\n Disabled by your configuration linters:\n " )
109- printLinters (disabledLCs )
133+ printLinters (disabledLinters )
110134
111135 return nil
112136}
0 commit comments