Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *configCommand) preRunE(cmd *cobra.Command, args []string) error {
// It only needs to know the path of the configuration file.
cfg := config.NewDefault()

loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts, cfg, args)
loader := config.NewLintersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts, cfg, args)

err := loader.Load(config.LoadOptions{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newFmtCommand(logger logutils.Log, info BuildInfo) *fmtCommand {
func (c *fmtCommand) persistentPreRunE(cmd *cobra.Command, args []string) error {
c.log.Infof("%s", c.buildInfo.String())

loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
loader := config.NewFormattersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)

err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newFormattersCommand(logger logutils.Log) *formattersCommand {
}

func (c *formattersCommand) preRunE(cmd *cobra.Command, args []string) error {
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
loader := config.NewFormattersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)

err := loader.Load(config.LoadOptions{Validation: true})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newLintersCommand(logger logutils.Log) *lintersCommand {
}

func (c *lintersCommand) preRunE(cmd *cobra.Command, args []string) error {
loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
loader := config.NewLintersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)

err := loader.Load(config.LoadOptions{Validation: true})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *runCommand) persistentPreRunE(cmd *cobra.Command, args []string) error

c.log.Infof("%s", c.buildInfo.String())

loader := config.NewLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)
loader := config.NewLintersLoader(c.log.Child(logutils.DebugKeyConfigReader), c.viper, cmd.Flags(), c.opts.LoaderOptions, c.cfg, args)

err := loader.Load(config.LoadOptions{CheckDeprecation: true, Validation: true})
if err != nil {
Expand Down
32 changes: 25 additions & 7 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (

var errConfigDisabled = errors.New("config is disabled by --no-config")

const (
modeLinters = "linters"
modeFormatters = "formatters"
)

type LoaderOptions struct {
Config string // Flag only. The path to the golangci config file, as specified with the --config argument.
NoConfig bool // Flag only.
Expand All @@ -33,9 +38,25 @@ type Loader struct {
fs *pflag.FlagSet

cfg *Config

mode string
}

func NewLintersLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderOptions, cfg *Config, args []string) *Loader {
loader := newLoader(log, v, fs, opts, cfg, args)
loader.mode = modeLinters

return loader
}

func NewLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderOptions, cfg *Config, args []string) *Loader {
func NewFormattersLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderOptions, cfg *Config, args []string) *Loader {
loader := newLoader(log, v, fs, opts, cfg, args)
loader.mode = modeFormatters

return loader
}

func newLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderOptions, cfg *Config, args []string) *Loader {
return &Loader{
BaseLoader: NewBaseLoader(log, v, opts, cfg, args),
fs: fs,
Expand All @@ -44,18 +65,15 @@ func NewLoader(log logutils.Log, v *viper.Viper, fs *pflag.FlagSet, opts LoaderO
}

func (l *Loader) Load(opts LoadOptions) error {
err := l.setConfigFile()
err := l.BaseLoader.Load()
if err != nil {
return err
}

err = l.parseConfig()
if err != nil {
return err
if l.mode == modeLinters {
l.applyStringSliceHack()
}

l.applyStringSliceHack()

if l.cfg.Linters.Exclusions.Generated == "" {
l.cfg.Linters.Exclusions.Generated = GeneratedModeStrict
}
Expand Down
Loading