Skip to content

feat: convert comma separated to slices #5468

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 4 commits into from
Feb 24, 2025
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
15 changes: 9 additions & 6 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ formatters:
extra-rules: true

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

golines:
# Target maximum line length.
Expand Down Expand Up @@ -2356,9 +2357,11 @@ linters-settings:
for-loops: true

predeclared:
# Comma-separated list of predeclared identifiers to not report on.
# Default: ""
ignore: "new,int"
# List of predeclared identifiers to not report on.
# Default: []
ignore:
- new
- int
# Include method names and field names in checks.
# Default: false
qualified-name: true
Expand Down
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ formatters:
- pattern: 'interface{}'
replacement: 'any'
goimports:
local-prefixes: github.com/golangci/golangci-lint
local-prefixes:
- github.com/golangci/golangci-lint

linters-settings:
depguard:
Expand Down
15 changes: 10 additions & 5 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1555,9 +1555,11 @@
"additionalProperties": false,
"properties": {
"local-prefixes": {
"description": "Put imports beginning with prefix after 3rd-party packages. It is a comma-separated list of prefixes.",
"type": "string",
"examples": ["github.com/org/project"]
"description": "Put imports beginning with prefix after 3rd-party packages. It is a list of prefixes.",
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -2413,8 +2415,11 @@
"additionalProperties": false,
"properties": {
"ignore": {
"description": "Comma-separated list of predeclared identifiers to not report on.",
"type": "string"
"description": "List of predeclared identifiers to not report on.",
"type": "array",
"items": {
"type": "string"
}
},
"qualified-name": {
"description": "Include method names and field names in checks.",
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/formatters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type GoFumptSettings struct {
}

type GoImportsSettings struct {
LocalPrefixes string `mapstructure:"local-prefixes"`
LocalPrefixes []string `mapstructure:"local-prefixes"`
}

type GoLinesSettings struct {
Expand Down
5 changes: 2 additions & 3 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ var defaultLintersSettings = LintersSettings{
ForLoops: false,
},
Predeclared: PredeclaredSettings{
Ignore: "",
Qualified: false,
},
SlogLint: SlogLintSettings{
Expand Down Expand Up @@ -715,8 +714,8 @@ type PreallocSettings struct {
}

type PredeclaredSettings struct {
Ignore string `mapstructure:"ignore"`
Qualified bool `mapstructure:"qualified-name"`
Ignore []string `mapstructure:"ignore"`
Qualified bool `mapstructure:"qualified-name"`
}

type PromlinterSettings struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/goformatters/goimports/goimports.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package goimports

import (
"strings"

"golang.org/x/tools/imports"

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

func New(settings *config.GoImportsSettings) *Formatter {
if settings != nil {
imports.LocalPrefix = settings.LocalPrefixes
imports.LocalPrefix = strings.Join(settings.LocalPrefixes, ",")
}

return &Formatter{}
Expand Down
3 changes: 2 additions & 1 deletion pkg/golinters/goimports/testdata/goimports_local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ formatters:
- goimports
settings:
goimports:
local-prefixes: github.com/golangci/golangci-lint
local-prefixes:
- github.com/golangci/golangci-lint
4 changes: 3 additions & 1 deletion pkg/golinters/predeclared/predeclared.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package predeclared

import (
"strings"

"github.com/nishanths/predeclared/passes/predeclared"
"golang.org/x/tools/go/analysis"

Expand All @@ -15,7 +17,7 @@ func New(settings *config.PredeclaredSettings) *goanalysis.Linter {
if settings != nil {
cfg = map[string]map[string]any{
a.Name: {
predeclared.IgnoreFlag: settings.Ignore,
predeclared.IgnoreFlag: strings.Join(settings.Ignore, ","),
predeclared.QualifiedFlag: settings.Qualified,
},
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/golinters/predeclared/testdata/predeclared_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ version: "2"

linters-settings:
predeclared:
ignore: "real,recover"
ignore:
- real
- recover
qualified-name: true
Loading