4
4
"errors"
5
5
"fmt"
6
6
"io/ioutil"
7
- "math"
8
7
9
8
"github.com/mgechev/revive/formatter"
10
9
@@ -13,10 +12,6 @@ import (
13
12
"github.com/mgechev/revive/rule"
14
13
)
15
14
16
- const (
17
- defaultConfidence = 0.8
18
- )
19
-
20
15
var defaultRules = []lint.Rule {
21
16
& rule.VarDeclarationsRule {},
22
17
& rule.PackageCommentsRule {},
@@ -86,7 +81,6 @@ var allRules = append([]lint.Rule{
86
81
& rule.NestedStructs {},
87
82
& rule.IfReturnRule {},
88
83
& rule.UselessBreak {},
89
- & rule.TimeEqualRule {},
90
84
}, defaultRules ... )
91
85
92
86
var allFormatters = []lint.Formatter {
@@ -133,26 +127,19 @@ func GetLintingRules(config *lint.Config) ([]lint.Rule, error) {
133
127
return lintingRules , nil
134
128
}
135
129
136
- func parseConfig (path string ) (* lint.Config , error ) {
137
- config := & lint.Config {
138
- Confidence : math .Inf (1 ),
139
- }
130
+ func parseConfig (path string , config * lint.Config ) error {
140
131
file , err := ioutil .ReadFile (path )
141
132
if err != nil {
142
- return nil , errors .New ("cannot read the config file" )
133
+ return errors .New ("cannot read the config file" )
143
134
}
144
135
_ , err = toml .Decode (string (file ), config )
145
136
if err != nil {
146
- return nil , fmt .Errorf ("cannot parse the config file: %v" , err )
137
+ return fmt .Errorf ("cannot parse the config file: %v" , err )
147
138
}
148
- return config , nil
139
+ return nil
149
140
}
150
141
151
142
func normalizeConfig (config * lint.Config ) {
152
- if config .Confidence == math .Inf (1 ) {
153
- config .Confidence = defaultConfidence
154
- }
155
-
156
143
if len (config .Rules ) == 0 {
157
144
config .Rules = map [string ]lint.RuleConfig {}
158
145
}
@@ -186,16 +173,23 @@ func normalizeConfig(config *lint.Config) {
186
173
}
187
174
}
188
175
176
+ const defaultConfidence = 0.8
177
+
189
178
// GetConfig yields the configuration
190
179
func GetConfig (configPath string ) (* lint.Config , error ) {
191
- config := defaultConfig ()
192
- if configPath != "" {
193
- var err error
194
- config , err = parseConfig (configPath )
180
+ var config = & lint.Config {}
181
+ switch {
182
+ case configPath != "" :
183
+ config .Confidence = defaultConfidence
184
+ err := parseConfig (configPath , config )
195
185
if err != nil {
196
186
return nil , err
197
187
}
188
+
189
+ default : // no configuration provided
190
+ config = defaultConfig ()
198
191
}
192
+
199
193
normalizeConfig (config )
200
194
return config , nil
201
195
}
@@ -216,7 +210,7 @@ func GetFormatter(formatterName string) (lint.Formatter, error) {
216
210
217
211
func defaultConfig () * lint.Config {
218
212
defaultConfig := lint.Config {
219
- Confidence : math . Inf ( 1 ) ,
213
+ Confidence : defaultConfidence ,
220
214
Severity : lint .SeverityWarning ,
221
215
Rules : map [string ]lint.RuleConfig {},
222
216
}
0 commit comments