@@ -2,6 +2,7 @@ package pkg
2
2
3
3
import (
4
4
"fmt"
5
+ "os"
5
6
"strings"
6
7
"sync"
7
8
@@ -55,15 +56,9 @@ func (lc LinterConfig) WithPresets(presets ...string) LinterConfig {
55
56
return lc
56
57
}
57
58
58
- func (lc LinterConfig ) WithDisabledByDefault () LinterConfig {
59
- lc .EnabledByDefault = false
60
- return lc
61
- }
62
-
63
59
func newLinterConfig (linter Linter ) LinterConfig {
64
60
return LinterConfig {
65
- Linter : linter ,
66
- EnabledByDefault : true ,
61
+ Linter : linter ,
67
62
}
68
63
}
69
64
@@ -86,11 +81,21 @@ func GetLinterConfig(name string) *LinterConfig {
86
81
return & lc
87
82
}
88
83
84
+ func enableLinterConfigs (lcs []LinterConfig , isEnabled func (lc * LinterConfig ) bool ) []LinterConfig {
85
+ var ret []LinterConfig
86
+ for _ , lc := range lcs {
87
+ lc .EnabledByDefault = isEnabled (& lc )
88
+ ret = append (ret , lc )
89
+ }
90
+
91
+ return ret
92
+ }
93
+
89
94
func GetAllSupportedLinterConfigs () []LinterConfig {
90
- return []LinterConfig {
95
+ lcs := []LinterConfig {
91
96
newLinterConfig (golinters.Govet {}).WithPresets (PresetBugs ),
92
97
newLinterConfig (golinters.Errcheck {}).WithFullImport ().WithPresets (PresetBugs ),
93
- newLinterConfig (golinters.Golint {}).WithDisabledByDefault (). WithPresets (PresetStyle ),
98
+ newLinterConfig (golinters.Golint {}).WithPresets (PresetStyle ),
94
99
95
100
newLinterConfig (golinters.Megacheck {StaticcheckEnabled : true }).WithSSA ().WithPresets (PresetBugs ),
96
101
newLinterConfig (golinters.Megacheck {UnusedEnabled : true }).WithSSA ().WithPresets (PresetUnused ),
@@ -99,20 +104,47 @@ func GetAllSupportedLinterConfigs() []LinterConfig {
99
104
newLinterConfig (golinters.Gas {}).WithFullImport ().WithPresets (PresetBugs ),
100
105
newLinterConfig (golinters.Structcheck {}).WithFullImport ().WithPresets (PresetUnused ),
101
106
newLinterConfig (golinters.Varcheck {}).WithFullImport ().WithPresets (PresetUnused ),
102
- newLinterConfig (golinters.Interfacer {}).WithDisabledByDefault (). WithSSA ().WithPresets (PresetStyle ),
103
- newLinterConfig (golinters.Unconvert {}).WithDisabledByDefault (). WithFullImport ().WithPresets (PresetStyle ),
107
+ newLinterConfig (golinters.Interfacer {}).WithSSA ().WithPresets (PresetStyle ),
108
+ newLinterConfig (golinters.Unconvert {}).WithFullImport ().WithPresets (PresetStyle ),
104
109
newLinterConfig (golinters.Ineffassign {}).WithPresets (PresetUnused ),
105
- newLinterConfig (golinters.Dupl {}).WithDisabledByDefault (). WithPresets (PresetStyle ),
106
- newLinterConfig (golinters.Goconst {}).WithDisabledByDefault (). WithPresets (PresetStyle ),
110
+ newLinterConfig (golinters.Dupl {}).WithPresets (PresetStyle ),
111
+ newLinterConfig (golinters.Goconst {}).WithPresets (PresetStyle ),
107
112
newLinterConfig (golinters.Deadcode {}).WithFullImport ().WithPresets (PresetUnused ),
108
- newLinterConfig (golinters.Gocyclo {}).WithDisabledByDefault (). WithPresets (PresetComplexity ),
113
+ newLinterConfig (golinters.Gocyclo {}).WithPresets (PresetComplexity ),
109
114
110
- newLinterConfig (golinters.Gofmt {}).WithDisabledByDefault (). WithPresets (PresetFormatting ),
111
- newLinterConfig (golinters.Gofmt {UseGoimports : true }).WithDisabledByDefault (). WithPresets (PresetFormatting ),
112
- newLinterConfig (golinters.Maligned {}).WithFullImport ().WithDisabledByDefault (). WithPresets (PresetPerformance ),
115
+ newLinterConfig (golinters.Gofmt {}).WithPresets (PresetFormatting ),
116
+ newLinterConfig (golinters.Gofmt {UseGoimports : true }).WithPresets (PresetFormatting ),
117
+ newLinterConfig (golinters.Maligned {}).WithFullImport ().WithPresets (PresetPerformance ),
113
118
newLinterConfig (golinters.Megacheck {GosimpleEnabled : true , UnusedEnabled : true , StaticcheckEnabled : true }).
114
- WithSSA ().WithPresets (PresetStyle , PresetBugs , PresetUnused ).WithDisabledByDefault (),
119
+ WithSSA ().WithPresets (PresetStyle , PresetBugs , PresetUnused ),
120
+ }
121
+
122
+ if os .Getenv ("GOLANGCI_COM_RUN" ) == "1" {
123
+ disabled := map [string ]bool {
124
+ "gocyclo" : true ,
125
+ "dupl" : true ,
126
+ "maligned" : true ,
127
+ }
128
+ return enableLinterConfigs (lcs , func (lc * LinterConfig ) bool {
129
+ return ! disabled [lc .Linter .Name ()]
130
+ })
115
131
}
132
+
133
+ enabled := map [string ]bool {
134
+ "govet" : true ,
135
+ "errcheck" : true ,
136
+ "staticcheck" : true ,
137
+ "unused" : true ,
138
+ "gosimple" : true ,
139
+ "gas" : true ,
140
+ "structcheck" : true ,
141
+ "varcheck" : true ,
142
+ "ineffassign" : true ,
143
+ "deadcode" : true ,
144
+ }
145
+ return enableLinterConfigs (lcs , func (lc * LinterConfig ) bool {
146
+ return enabled [lc .Linter .Name ()]
147
+ })
116
148
}
117
149
118
150
func getAllSupportedLinters () []Linter {
0 commit comments