Skip to content

Commit 18e322e

Browse files
authored
feat: convert comma separated to slices (#5468)
1 parent bed771a commit 18e322e

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

.golangci.next.reference.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,11 @@ formatters:
398398
extra-rules: true
399399

400400
goimports:
401-
# A comma-separated list of prefixes, which, if set, checks import paths
401+
# A list of prefixes, which, if set, checks import paths
402402
# with the given prefixes are grouped after 3rd-party packages.
403-
# Default: ""
404-
local-prefixes: github.com/org/project
403+
# Default: []
404+
local-prefixes:
405+
- github.com/org/project
405406

406407
golines:
407408
# Target maximum line length.
@@ -2356,9 +2357,11 @@ linters-settings:
23562357
for-loops: true
23572358

23582359
predeclared:
2359-
# Comma-separated list of predeclared identifiers to not report on.
2360-
# Default: ""
2361-
ignore: "new,int"
2360+
# List of predeclared identifiers to not report on.
2361+
# Default: []
2362+
ignore:
2363+
- new
2364+
- int
23622365
# Include method names and field names in checks.
23632366
# Default: false
23642367
qualified-name: true

.golangci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ formatters:
114114
- pattern: 'interface{}'
115115
replacement: 'any'
116116
goimports:
117-
local-prefixes: github.com/golangci/golangci-lint
117+
local-prefixes:
118+
- github.com/golangci/golangci-lint
118119

119120
linters-settings:
120121
depguard:

jsonschema/golangci.next.jsonschema.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1555,9 +1555,11 @@
15551555
"additionalProperties": false,
15561556
"properties": {
15571557
"local-prefixes": {
1558-
"description": "Put imports beginning with prefix after 3rd-party packages. It is a comma-separated list of prefixes.",
1559-
"type": "string",
1560-
"examples": ["github.com/org/project"]
1558+
"description": "Put imports beginning with prefix after 3rd-party packages. It is a list of prefixes.",
1559+
"type": "array",
1560+
"items": {
1561+
"type": "string"
1562+
}
15611563
}
15621564
}
15631565
},
@@ -2413,8 +2415,11 @@
24132415
"additionalProperties": false,
24142416
"properties": {
24152417
"ignore": {
2416-
"description": "Comma-separated list of predeclared identifiers to not report on.",
2417-
"type": "string"
2418+
"description": "List of predeclared identifiers to not report on.",
2419+
"type": "array",
2420+
"items": {
2421+
"type": "string"
2422+
}
24182423
},
24192424
"qualified-name": {
24202425
"description": "Include method names and field names in checks.",

pkg/config/formatters_settings.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type GoFumptSettings struct {
5151
}
5252

5353
type GoImportsSettings struct {
54-
LocalPrefixes string `mapstructure:"local-prefixes"`
54+
LocalPrefixes []string `mapstructure:"local-prefixes"`
5555
}
5656

5757
type GoLinesSettings struct {

pkg/config/linters_settings.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ var defaultLintersSettings = LintersSettings{
128128
ForLoops: false,
129129
},
130130
Predeclared: PredeclaredSettings{
131-
Ignore: "",
132131
Qualified: false,
133132
},
134133
SlogLint: SlogLintSettings{
@@ -715,8 +714,8 @@ type PreallocSettings struct {
715714
}
716715

717716
type PredeclaredSettings struct {
718-
Ignore string `mapstructure:"ignore"`
719-
Qualified bool `mapstructure:"qualified-name"`
717+
Ignore []string `mapstructure:"ignore"`
718+
Qualified bool `mapstructure:"qualified-name"`
720719
}
721720

722721
type PromlinterSettings struct {

pkg/goformatters/goimports/goimports.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package goimports
22

33
import (
4+
"strings"
5+
46
"golang.org/x/tools/imports"
57

68
"github.com/golangci/golangci-lint/pkg/config"
@@ -12,7 +14,7 @@ type Formatter struct{}
1214

1315
func New(settings *config.GoImportsSettings) *Formatter {
1416
if settings != nil {
15-
imports.LocalPrefix = settings.LocalPrefixes
17+
imports.LocalPrefix = strings.Join(settings.LocalPrefixes, ",")
1618
}
1719

1820
return &Formatter{}

pkg/golinters/goimports/testdata/goimports_local.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ formatters:
55
- goimports
66
settings:
77
goimports:
8-
local-prefixes: github.com/golangci/golangci-lint
8+
local-prefixes:
9+
- github.com/golangci/golangci-lint

pkg/golinters/predeclared/predeclared.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package predeclared
22

33
import (
4+
"strings"
5+
46
"github.com/nishanths/predeclared/passes/predeclared"
57
"golang.org/x/tools/go/analysis"
68

@@ -15,7 +17,7 @@ func New(settings *config.PredeclaredSettings) *goanalysis.Linter {
1517
if settings != nil {
1618
cfg = map[string]map[string]any{
1719
a.Name: {
18-
predeclared.IgnoreFlag: settings.Ignore,
20+
predeclared.IgnoreFlag: strings.Join(settings.Ignore, ","),
1921
predeclared.QualifiedFlag: settings.Qualified,
2022
},
2123
}

pkg/golinters/predeclared/testdata/predeclared_custom.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ version: "2"
22

33
linters-settings:
44
predeclared:
5-
ignore: "real,recover"
5+
ignore:
6+
- real
7+
- recover
68
qualified-name: true

0 commit comments

Comments
 (0)