Skip to content

Commit d9ea961

Browse files
committed
chore: rename forbidigo options
1 parent d864d1e commit d9ea961

File tree

7 files changed

+27
-67
lines changed

7 files changed

+27
-67
lines changed

Diff for: .golangci.next.reference.yml

+5-5
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

Diff for: jsonschema/golangci.next.jsonschema.json

+13-21
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
}

Diff for: pkg/config/linters_settings.go

+1-34
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"`

Diff for: 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
}

Diff for: 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!)?

Diff for: 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!

Diff for: test/testdata/configs/path-except.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ 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!)?
88

99
linters:
1010
exclusions:

0 commit comments

Comments
 (0)