Skip to content

fix config validation #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2018
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 Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ func (e *Executor) parseConfig(cmd *cobra.Command) {
viper.SetConfigFile(configFile)
}

commandLineConfig := *e.cfg // make copy

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
return
Expand All @@ -334,22 +336,22 @@ func (e *Executor) parseConfig(cmd *cobra.Command) {
log.Fatalf("Can't unmarshal config by viper: %s", err)
}

if err := e.validateConfig(); err != nil {
if err := e.validateConfig(&commandLineConfig); err != nil {
log.Fatal(err)
}
}

func (e *Executor) validateConfig() error {
func (e *Executor) validateConfig(commandLineConfig *config.Config) error {
c := e.cfg
if len(c.Run.Args) != 0 {
return errors.New("option run.args in config aren't supported now")
return errors.New("option run.args in config isn't supported now")
}

if c.Run.CPUProfilePath != "" {
if commandLineConfig.Run.CPUProfilePath == "" && c.Run.CPUProfilePath != "" {
return errors.New("option run.cpuprofilepath in config isn't allowed")
}

if c.Run.IsVerbose {
if !commandLineConfig.Run.IsVerbose && c.Run.IsVerbose {
return errors.New("can't set run.verbose option with config: only on command-line")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (r SimpleRunner) runGo(ctx context.Context, linters []Linter, lintCtx *goli
finishedN := 0
for res := range lintResultsCh {
if res.err != nil {
logrus.Warnf("Can't run linter %s: %s", res.linter.Name(), res.err)
logrus.Infof("Can't run linter %s: %s", res.linter.Name(), res.err)
continue
}

Expand Down
4 changes: 3 additions & 1 deletion vendor/github.com/golangci/go-tools/lint/lint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.