Skip to content

Commit 1fdcbdd

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

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

pkg/commands/run.go

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

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

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)