Skip to content

Commit a79eeab

Browse files
authored
feat: configuration options renaming (#5462)
1 parent e651eee commit a79eeab

File tree

13 files changed

+67
-109
lines changed

13 files changed

+67
-109
lines changed

.golangci.next.reference.yml

+16-16
Original file line numberDiff line numberDiff line change
@@ -708,20 +708,20 @@ linters-settings:
708708
# Default: ["^(fmt\\.Print(|f|ln)|print|println)$"]
709709
forbid:
710710
# Built-in bootstrapping functions.
711-
- ^print(ln)?$
711+
- pattern: ^print(ln)?$
712712
# Optional message that gets included in error reports.
713-
- p: ^fmt\.Print.*$
713+
- pattern: ^fmt\.Print.*$
714714
msg: Do not commit print statements.
715715
# Alternatively, put messages at the end of the regex, surrounded by `(# )?`
716716
# Escape any special characters. Those messages get included in error reports.
717-
- 'fmt\.Print.*(# Do not commit print statements\.)?'
717+
- pattern: 'fmt\.Print.*(# Do not commit print statements\.)?'
718718
# Forbid spew Dump, whether it is called as function or method.
719719
# Depends on analyze-types below.
720-
- ^spew\.(ConfigState\.)?Dump$
720+
- pattern: ^spew\.(ConfigState\.)?Dump$
721721
# The package name might be ambiguous.
722722
# The full import path can be used as additional criteria.
723723
# Depends on analyze-types below.
724-
- p: ^v1.Dump$
724+
- pattern: ^v1.Dump$
725725
pkg: ^example.com/pkg/api/v1$
726726
# Exclude godoc examples from forbidigo checks.
727727
# Default: true
@@ -1530,7 +1530,7 @@ linters-settings:
15301530
reason: "testing if blocked version constraint works."
15311531
# Set to true to raise lint issues for packages that are loaded from a local path via replace directive.
15321532
# Default: false
1533-
local_replace_directives: false
1533+
local-replace-directives: false
15341534

15351535
gosimple:
15361536
# Sxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks
@@ -2215,7 +2215,7 @@ linters-settings:
22152215
# Typos to ignore.
22162216
# Should be in lower case.
22172217
# Default: []
2218-
ignore-words:
2218+
ignore-rules:
22192219
- someword
22202220
# Extra word corrections.
22212221
# `typo` and `correction` should only contain letters.
@@ -2383,9 +2383,9 @@ linters-settings:
23832383
# Comma-separated list of predeclared identifiers to not report on.
23842384
# Default: ""
23852385
ignore: "new,int"
2386-
# Include method names and field names (i.e., qualified names) in checks.
2386+
# Include method names and field names in checks.
23872387
# Default: false
2388-
q: true
2388+
qualified-name: true
23892389

23902390
promlinter:
23912391
# Promlinter cannot infer all metrics name in static analysis.
@@ -3878,9 +3878,9 @@ linters-settings:
38783878

38793879
wrapcheck:
38803880
# An array of strings specifying additional substrings of signatures to ignore.
3881-
# Unlike 'ignoreSigs', this option extends the default set (or the set specified in 'ignoreSigs') without replacing it entirely.
3881+
# Unlike 'ignore-sigs', this option extends the default set (or the set specified in 'ignore-sigs') without replacing it entirely.
38823882
# This allows you to add specific signatures to the ignore list
3883-
# while retaining the defaults or any items in 'ignoreSigs'.
3883+
# while retaining the defaults or any items in 'ignore-sigs'.
38843884
# Default: []
38853885
extra-ignore-sigs:
38863886
- .CustomError(
@@ -3890,7 +3890,7 @@ linters-settings:
38903890
# If this set, it will override the default set of ignored signatures.
38913891
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
38923892
# Default: [".Errorf(", "errors.New(", "errors.Unwrap(", "errors.Join(", ".Wrap(", ".Wrapf(", ".WithMessage(", ".WithMessagef(", ".WithStack("]
3893-
ignoreSigs:
3893+
ignore-sigs:
38943894
- .Errorf(
38953895
- errors.New(
38963896
- errors.Unwrap(
@@ -3902,16 +3902,16 @@ linters-settings:
39023902
- .WithStack(
39033903
# An array of strings that specify regular expressions of signatures to ignore.
39043904
# Default: []
3905-
ignoreSigRegexps:
3905+
ignore-sig-regexps:
39063906
- \.New.*Error\(
39073907
# An array of strings that specify globs of packages to ignore.
39083908
# Default: []
3909-
ignorePackageGlobs:
3909+
ignore-package-globs:
39103910
- encoding/*
39113911
- github.com/pkg/*
39123912
# An array of strings that specify regular expressions of interfaces to ignore.
39133913
# Default: []
3914-
ignoreInterfaceRegexps:
3914+
ignore-interface-regexps:
39153915
- ^(?i)c(?-i)ach(ing|e)
39163916

39173917
wsl:
@@ -4236,7 +4236,7 @@ severity:
42364236
# `@linter` can be used as severity value to keep the severity from linters (e.g. revive, gosec, ...)
42374237
#
42384238
# Default: ""
4239-
default-severity: error
4239+
default: error
42404240

42414241
# If set to true `severity-rules` regular expressions become case-sensitive.
42424242
# Default: false

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ linters-settings:
187187
line-length: 140
188188
misspell:
189189
locale: US
190-
ignore-words:
190+
ignore-rules:
191191
- "importas" # linter name
192192
nolintlint:
193193
allow-unused: false # report any unused nolint directives

jsonschema/golangci.next.jsonschema.json

+24-32
Original file line numberDiff line numberDiff line change
@@ -942,31 +942,23 @@
942942
"forbid": {
943943
"description": "List of identifiers to forbid (written using `regexp`)",
944944
"type": "array",
945-
"examples": ["^print(ln)?$"],
946945
"items": {
947-
"anyOf": [
948-
{
946+
"type": "object",
947+
"additionalProperties": false,
948+
"properties": {
949+
"pattern": {
950+
"description": "Pattern",
949951
"type": "string"
950952
},
951-
{
952-
"type": "object",
953-
"additionalProperties": false,
954-
"properties": {
955-
"p": {
956-
"description": "Pattern",
957-
"type": "string"
958-
},
959-
"pkg": {
960-
"description": "Package",
961-
"type": "string"
962-
},
963-
"msg": {
964-
"description": "Message",
965-
"type": "string"
966-
}
967-
}
953+
"pkg": {
954+
"description": "Package",
955+
"type": "string"
956+
},
957+
"msg": {
958+
"description": "Message",
959+
"type": "string"
968960
}
969-
]
961+
}
970962
}
971963
}
972964
}
@@ -1727,7 +1719,7 @@
17271719
}
17281720
}
17291721
},
1730-
"local_replace_directives": {
1722+
"local-replace-directives": {
17311723
"description": "Raise lint issues if loading local path with replace directive",
17321724
"type": "boolean",
17331725
"default": true
@@ -2135,8 +2127,8 @@
21352127
"locale": {
21362128
"enum": ["US", "UK"]
21372129
},
2138-
"ignore-words": {
2139-
"description": "List of words to ignore.",
2130+
"ignore-rules": {
2131+
"description": "List of rules to ignore.",
21402132
"type": "array",
21412133
"items": {
21422134
"type": "string"
@@ -2459,8 +2451,8 @@
24592451
"description": "Comma-separated list of predeclared identifiers to not report on.",
24602452
"type": "string"
24612453
},
2462-
"q": {
2463-
"description": "Include method names and field names (i.e., qualified names) in checks.",
2454+
"qualified-name": {
2455+
"description": "Include method names and field names in checks.",
24642456
"type": "boolean",
24652457
"default": false
24662458
}
@@ -3586,7 +3578,7 @@
35863578
"type": "string"
35873579
}
35883580
},
3589-
"ignoreSigs": {
3581+
"ignore-sigs": {
35903582
"description": "An array of strings which specify substrings of signatures to ignore.",
35913583
"default": [
35923584
".Errorf(",
@@ -3603,23 +3595,23 @@
36033595
"type": "string"
36043596
}
36053597
},
3606-
"ignoreSigRegexps": {
3598+
"ignore-sig-regexps": {
36073599
"description": "An array of strings which specify regular expressions of signatures to ignore.",
36083600
"default": [""],
36093601
"type": "array",
36103602
"items": {
36113603
"type": "string"
36123604
}
36133605
},
3614-
"ignorePackageGlobs": {
3606+
"ignore-package-globs": {
36153607
"description": "An array of glob patterns which, if any match the package of the function returning the error, will skip wrapcheck analysis for this error.",
36163608
"default": [""],
36173609
"type": "array",
36183610
"items": {
36193611
"type": "string"
36203612
}
36213613
},
3622-
"ignoreInterfaceRegexps": {
3614+
"ignore-interface-regexps": {
36233615
"description": "An array of glob patterns which, if matched to an underlying interface name, will ignore unwrapped errors returned from a function whose call is defined on the given interface.",
36243616
"default": [""],
36253617
"type": "array",
@@ -4425,7 +4417,7 @@
44254417
"type": "object",
44264418
"additionalProperties": false,
44274419
"properties": {
4428-
"default-severity": {
4420+
"default": {
44294421
"description": "Set the default severity for issues. If severity rules are defined and the issues do not match or no severity is provided to the rule this will be the default severity applied. Severities should match the supported severity names of the selected out format.",
44304422
"type": "string",
44314423
"default": ""
@@ -4476,7 +4468,7 @@
44764468
"default": []
44774469
}
44784470
},
4479-
"required": ["default-severity"]
4471+
"required": ["default"]
44804472
}
44814473
}
44824474
}

pkg/config/linters_settings.go

+12-47
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package config
22

33
import (
4-
"encoding"
54
"errors"
65
"fmt"
76
"runtime"
8-
9-
"gopkg.in/yaml.v3"
107
)
118

129
var defaultLintersSettings = LintersSettings{
@@ -425,42 +422,12 @@ type ForbidigoSettings struct {
425422
AnalyzeTypes bool `mapstructure:"analyze-types"`
426423
}
427424

428-
var _ encoding.TextUnmarshaler = &ForbidigoPattern{}
429-
430-
// ForbidigoPattern corresponds to forbidigo.pattern and adds mapstructure support.
431-
// The YAML field names must match what forbidigo expects.
432425
type ForbidigoPattern struct {
433-
// patternString gets populated when the config contains a string as entry in ForbidigoSettings.Forbid[]
434-
// because ForbidigoPattern implements encoding.TextUnmarshaler
435-
// and the reader uses the mapstructure.TextUnmarshallerHookFunc as decoder hook.
436-
//
437-
// If the entry is a map, then the other fields are set as usual by mapstructure.
438-
patternString string
439-
440-
Pattern string `yaml:"p" mapstructure:"p"`
426+
Pattern string `yaml:"p" mapstructure:"pattern"`
441427
Package string `yaml:"pkg,omitempty" mapstructure:"pkg,omitempty"`
442428
Msg string `yaml:"msg,omitempty" mapstructure:"msg,omitempty"`
443429
}
444430

445-
func (p *ForbidigoPattern) UnmarshalText(text []byte) error {
446-
// Validation happens when instantiating forbidigo.
447-
p.patternString = string(text)
448-
return nil
449-
}
450-
451-
// MarshalString converts the pattern into a string as needed by forbidigo.NewLinter.
452-
//
453-
// MarshalString is intentionally not called MarshalText,
454-
// although it has the same signature
455-
// because implementing encoding.TextMarshaler led to infinite recursion when yaml.Marshal called MarshalText.
456-
func (p *ForbidigoPattern) MarshalString() ([]byte, error) {
457-
if p.patternString != "" {
458-
return []byte(p.patternString), nil
459-
}
460-
461-
return yaml.Marshal(p)
462-
}
463-
464431
type FunlenSettings struct {
465432
Lines int `mapstructure:"lines"`
466433
Statements int `mapstructure:"statements"`
@@ -563,7 +530,7 @@ type GoModGuardSettings struct {
563530
Version string `mapstructure:"version"`
564531
Reason string `mapstructure:"reason"`
565532
} `mapstructure:"versions"`
566-
LocalReplaceDirectives bool `mapstructure:"local_replace_directives"`
533+
LocalReplaceDirectives bool `mapstructure:"local-replace-directives"`
567534
} `mapstructure:"blocked"`
568535
}
569536

@@ -673,11 +640,10 @@ type MakezeroSettings struct {
673640
}
674641

675642
type MisspellSettings struct {
676-
Mode string `mapstructure:"mode"`
677-
Locale string `mapstructure:"locale"`
678-
ExtraWords []MisspellExtraWords `mapstructure:"extra-words"`
679-
// TODO(ldez): v2 the option must be renamed to `IgnoredRules`.
680-
IgnoreWords []string `mapstructure:"ignore-words"`
643+
Mode string `mapstructure:"mode"`
644+
Locale string `mapstructure:"locale"`
645+
ExtraWords []MisspellExtraWords `mapstructure:"extra-words"`
646+
IgnoreRules []string `mapstructure:"ignore-rules"`
681647
}
682648

683649
type MisspellExtraWords struct {
@@ -758,7 +724,7 @@ type PreallocSettings struct {
758724

759725
type PredeclaredSettings struct {
760726
Ignore string `mapstructure:"ignore"`
761-
Qualified bool `mapstructure:"q"`
727+
Qualified bool `mapstructure:"qualified-name"`
762728
}
763729

764730
type PromlinterSettings struct {
@@ -988,12 +954,11 @@ type WhitespaceSettings struct {
988954
}
989955

990956
type WrapcheckSettings struct {
991-
ExtraIgnoreSigs []string `mapstructure:"extra-ignore-sigs"`
992-
// TODO(ldez): v2 the options must be renamed to use hyphen.
993-
IgnoreSigs []string `mapstructure:"ignoreSigs"`
994-
IgnoreSigRegexps []string `mapstructure:"ignoreSigRegexps"`
995-
IgnorePackageGlobs []string `mapstructure:"ignorePackageGlobs"`
996-
IgnoreInterfaceRegexps []string `mapstructure:"ignoreInterfaceRegexps"`
957+
ExtraIgnoreSigs []string `mapstructure:"extra-ignore-sigs"`
958+
IgnoreSigs []string `mapstructure:"ignore-sigs"`
959+
IgnoreSigRegexps []string `mapstructure:"ignore-sig-regexps"`
960+
IgnorePackageGlobs []string `mapstructure:"ignore-package-globs"`
961+
IgnoreInterfaceRegexps []string `mapstructure:"ignore-interface-regexps"`
997962
}
998963

999964
type WSLSettings struct {

pkg/config/severity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
const severityRuleMinConditionsCount = 1
99

1010
type Severity struct {
11-
Default string `mapstructure:"default-severity"`
11+
Default string `mapstructure:"default"`
1212
CaseSensitive bool `mapstructure:"case-sensitive"`
1313
Rules []SeverityRule `mapstructure:"rules"`
1414
}

pkg/golinters/forbidigo/forbidigo.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/ashanbrown/forbidigo/forbidigo"
77
"golang.org/x/tools/go/analysis"
8+
"gopkg.in/yaml.v3"
89

910
"github.com/golangci/golangci-lint/pkg/config"
1011
"github.com/golangci/golangci-lint/pkg/goanalysis"
@@ -49,7 +50,7 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) error
4950
// Convert patterns back to strings because that is what NewLinter accepts.
5051
var patterns []string
5152
for _, pattern := range settings.Forbid {
52-
buffer, err := pattern.MarshalString()
53+
buffer, err := yaml.Marshal(pattern)
5354
if err != nil {
5455
return err
5556
}

pkg/golinters/forbidigo/testdata/forbidigo.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ version: "2"
33
linters-settings:
44
forbidigo:
55
forbid:
6-
- fmt\.Print.*
7-
- time.Sleep(# no sleeping!)?
6+
- pattern: fmt\.Print.*
7+
- pattern: time.Sleep(# no sleeping!)?

pkg/golinters/forbidigo/testdata/forbidigo_struct.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ linters-settings:
44
forbidigo:
55
analyze-types: true
66
forbid:
7-
- p: fmt\.Print.*
7+
- pattern: fmt\.Print.*
88
pkg: ^fmt$
9-
- p: time.Sleep
9+
- pattern: time.Sleep
1010
msg: no sleeping!

0 commit comments

Comments
 (0)