Skip to content

Commit 8a38c4d

Browse files
committed
fix: comma in exclude pattern leads to unexpected results
1 parent 5d10450 commit 8a38c4d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

pkg/commands/run.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
213213

214214
// Issues config
215215
ic := &cfg.Issues
216+
// FIXME here
216217
fs.StringSliceVarP(&ic.ExcludePatterns, "exclude", "e", nil, wh("Exclude issue by regexp"))
217218
fs.BoolVar(&ic.UseDefaultExcludes, "exclude-use-default", true, getDefaultIssueExcludeHelp())
218219
fs.BoolVar(&ic.ExcludeCaseSensitive, "exclude-case-sensitive", false, wh("If set to true exclude "+
@@ -313,8 +314,24 @@ func fixSlicesFlags(fs *pflag.FlagSet) {
313314
return
314315
}
315316

317+
// custom join to handle string with comma.
318+
var g string
319+
for i, v := range s {
320+
if strings.Contains(v, ",") {
321+
// add quotes to escape comma because spf13/pflag use a CSV parser:
322+
// https://github.com/spf13/pflag/blob/85dd5c8bc61cfa382fecd072378089d4e856579d/string_slice.go#L43
323+
g += `"` + v + `"`
324+
} else {
325+
g += v
326+
}
327+
328+
if i < len(s)-1 {
329+
g += ","
330+
}
331+
}
332+
316333
// calling Set sets Changed to true: next Set calls will append, not overwrite
317-
_ = f.Value.Set(strings.Join(s, ","))
334+
_ = f.Value.Set(g)
318335
})
319336
}
320337

pkg/config/reader.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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)