mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
dev: remove unrelated flags from config and linters command (#4284)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
4ea9468cd6
commit
a727aa5780
6 changed files with 91 additions and 62 deletions
|
@ -2,10 +2,13 @@ package commands
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
||||
)
|
||||
|
||||
|
@ -17,8 +20,25 @@ func (e *Executor) initLinters() {
|
|||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
RunE: e.executeLinters,
|
||||
}
|
||||
|
||||
fs := e.lintersCmd.Flags()
|
||||
fs.SortFlags = false // sort them as they are defined here
|
||||
|
||||
initConfigFileFlagSet(fs, &e.cfg.Run)
|
||||
e.initLintersFlagSet(fs, &e.cfg.Linters)
|
||||
|
||||
e.rootCmd.AddCommand(e.lintersCmd)
|
||||
e.initRunConfiguration(e.lintersCmd)
|
||||
}
|
||||
|
||||
func (e *Executor) initLintersFlagSet(fs *pflag.FlagSet, cfg *config.Linters) {
|
||||
fs.StringSliceVarP(&cfg.Disable, "disable", "D", nil, wh("Disable specific linter"))
|
||||
fs.BoolVar(&cfg.DisableAll, "disable-all", false, wh("Disable all linters"))
|
||||
fs.StringSliceVarP(&cfg.Enable, "enable", "E", nil, wh("Enable specific linter"))
|
||||
fs.BoolVar(&cfg.EnableAll, "enable-all", false, wh("Enable all linters"))
|
||||
fs.BoolVar(&cfg.Fast, "fast", false, wh("Enable only fast linters from enabled linters set (first run won't be fast)"))
|
||||
fs.StringSliceVarP(&cfg.Presets, "presets", "p", nil,
|
||||
wh(fmt.Sprintf("Enable presets (%s) of linters. Run 'golangci-lint help linters' to see "+
|
||||
"them. This option implies option --disable-all", strings.Join(e.DBManager.AllPresets(), "|"))))
|
||||
}
|
||||
|
||||
// executeLinters runs the 'linters' CLI command, which displays the supported linters.
|
||||
|
@ -28,18 +48,9 @@ func (e *Executor) executeLinters(_ *cobra.Command, _ []string) error {
|
|||
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
|
||||
|
@ -47,9 +58,13 @@ func (e *Executor) executeLinters(_ *cobra.Command, _ []string) error {
|
|||
|
||||
if enabledLintersMap[lc.Name()] == nil {
|
||||
disabledLCs = append(disabledLCs, lc)
|
||||
} else {
|
||||
enabledLinters = append(enabledLinters, lc)
|
||||
}
|
||||
}
|
||||
|
||||
color.Green("Enabled by your configuration linters:\n")
|
||||
printLinterConfigs(enabledLinters)
|
||||
color.Red("\nDisabled by your configuration linters:\n")
|
||||
printLinterConfigs(disabledLCs)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue