|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding" |
5 | 4 | "errors" |
6 | 5 | "fmt" |
7 | 6 | "runtime" |
8 | | - |
9 | | - "gopkg.in/yaml.v3" |
10 | 7 | ) |
11 | 8 |
|
12 | 9 | var defaultLintersSettings = LintersSettings{ |
@@ -425,42 +422,12 @@ type ForbidigoSettings struct { |
425 | 422 | AnalyzeTypes bool `mapstructure:"analyze-types"` |
426 | 423 | } |
427 | 424 |
|
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. |
432 | 425 | 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"` |
441 | 427 | Package string `yaml:"pkg,omitempty" mapstructure:"pkg,omitempty"` |
442 | 428 | Msg string `yaml:"msg,omitempty" mapstructure:"msg,omitempty"` |
443 | 429 | } |
444 | 430 |
|
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 | | - |
464 | 431 | type FunlenSettings struct { |
465 | 432 | Lines int `mapstructure:"lines"` |
466 | 433 | Statements int `mapstructure:"statements"` |
|
0 commit comments