Skip to content

Commit 9cb902c

Browse files
authored
fix: comma in exclude pattern leads to unexpected results (#1917)
1 parent 2c00832 commit 9cb902c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pkg/commands/run.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,15 @@ func fixSlicesFlags(fs *pflag.FlagSet) {
313313
return
314314
}
315315

316+
var safe []string
317+
for _, v := range s {
318+
// add quotes to escape comma because spf13/pflag use a CSV parser:
319+
// https://github.com/spf13/pflag/blob/85dd5c8bc61cfa382fecd072378089d4e856579d/string_slice.go#L43
320+
safe = append(safe, `"`+v+`"`)
321+
}
322+
316323
// calling Set sets Changed to true: next Set calls will append, not overwrite
317-
_ = f.Value.Set(strings.Join(s, ","))
324+
_ = f.Value.Set(strings.Join(safe, ","))
318325
})
319326
}
320327

pkg/config/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"path/filepath"
88
"strings"
99

10-
homedir "github.com/mitchellh/go-homedir"
10+
"github.com/mitchellh/go-homedir"
1111
"github.com/spf13/viper"
1212

1313
"github.com/golangci/golangci-lint/pkg/fsutils"

pkg/lint/runner.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s
237237

238238
func getExcludeProcessor(cfg *config.Issues) processors.Processor {
239239
var excludeTotalPattern string
240-
excludeGlobalPatterns := cfg.ExcludePatterns
241-
if len(excludeGlobalPatterns) != 0 {
242-
excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludeGlobalPatterns, "|"))
240+
241+
if len(cfg.ExcludePatterns) != 0 {
242+
excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(cfg.ExcludePatterns, "|"))
243243
}
244244

245245
var excludeProcessor processors.Processor

0 commit comments

Comments
 (0)