Skip to content

Commit 9803f18

Browse files
committed
feat: new exclusion configuration
1 parent 8f859d4 commit 9803f18

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

jsonschema/golangci.next.jsonschema.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,6 +3884,70 @@
38843884
"description": "Enable run of fast linters.",
38853885
"type": "boolean",
38863886
"default": false
3887+
},
3888+
"exclusions":{
3889+
"type": "object",
3890+
"additionalProperties": false,
3891+
"properties": {
3892+
"generated": {
3893+
"enum": ["strict", "lax", "disable"],
3894+
"default": "lax"
3895+
},
3896+
"warn-unused": {
3897+
"type": "boolean",
3898+
"default": false
3899+
},
3900+
"default": {
3901+
"type": "array",
3902+
"items": {
3903+
"enum": [
3904+
"comments",
3905+
"stdErrorHandling",
3906+
"commonFalsePositives",
3907+
"legacy"
3908+
]
3909+
}
3910+
},
3911+
"rules": {
3912+
"type": "array",
3913+
"items": {
3914+
"type": "object",
3915+
"properties": {
3916+
"path": {
3917+
"type": "string"
3918+
},
3919+
"path-except": {
3920+
"type": "string"
3921+
},
3922+
"linters": {
3923+
"type": "array",
3924+
"items": {
3925+
"$ref": "#/definitions/linters"
3926+
}
3927+
},
3928+
"text": {
3929+
"type": "string"
3930+
},
3931+
"source": {
3932+
"type": "string"
3933+
}
3934+
},
3935+
"anyOf": [
3936+
{ "required": ["path"] },
3937+
{ "required": ["path-except"] },
3938+
{ "required": ["linters"] },
3939+
{ "required": ["text"] },
3940+
{ "required": ["source"] }
3941+
]
3942+
}
3943+
},
3944+
"paths": {
3945+
"type": "array",
3946+
"items": {
3947+
"type": "string"
3948+
}
3949+
}
3950+
}
38873951
}
38883952
}
38893953
},

pkg/config/linters.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type Linters struct {
1313
Fast bool
1414

1515
Presets []string
16+
17+
LinterExclusions LinterExclusions `mapstructure:"exclusions"`
1618
}
1719

1820
func (l *Linters) Validate() error {

pkg/config/linters_exclusions.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package config
2+
3+
type LinterExclusions struct {
4+
Generated string `mapstructure:"generated"`
5+
WarnUnused bool `mapstructure:"warn-unused"`
6+
Default []string `mapstructure:"default"`
7+
Rules []ExcludeRule `mapstructure:"rules"`
8+
Paths []string `mapstructure:"paths"`
9+
}

pkg/config/loader.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ func (l *Loader) Load(opts LoadOptions) error {
6868

6969
l.applyStringSliceHack()
7070

71+
if l.cfg.Linters.LinterExclusions.Generated == "" {
72+
// This is always non-empty because of the flag default value.
73+
if l.cfg.Issues.ExcludeGenerated != "" {
74+
l.cfg.Linters.LinterExclusions.Generated = l.cfg.Issues.ExcludeGenerated
75+
} else {
76+
l.cfg.Linters.LinterExclusions.Generated = "strict"
77+
}
78+
}
79+
80+
if l.cfg.Issues.UseDefaultExcludes {
81+
l.cfg.Linters.LinterExclusions.Default = []string{"comments", "stdErrorHandling", "commonFalsePositives", "legacy"}
82+
}
83+
84+
if len(l.cfg.Issues.ExcludeRules) > 0 {
85+
l.cfg.Linters.LinterExclusions.Rules = append(l.cfg.Linters.LinterExclusions.Rules, l.cfg.Issues.ExcludeRules...)
86+
}
87+
7188
if opts.CheckDeprecation {
7289
err = l.handleDeprecation()
7390
if err != nil {

0 commit comments

Comments
 (0)