Skip to content

Commit 12e4e8c

Browse files
chavacavamgechev
authored andcommitted
Update config.go
removes use of `math.Inf(1)`
1 parent c3af594 commit 12e4e8c

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

config/config.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"io/ioutil"
7-
"math"
87

98
"github.com/mgechev/revive/formatter"
109

@@ -13,10 +12,6 @@ import (
1312
"github.com/mgechev/revive/rule"
1413
)
1514

16-
const (
17-
defaultConfidence = 0.8
18-
)
19-
2015
var defaultRules = []lint.Rule{
2116
&rule.VarDeclarationsRule{},
2217
&rule.PackageCommentsRule{},
@@ -86,7 +81,6 @@ var allRules = append([]lint.Rule{
8681
&rule.NestedStructs{},
8782
&rule.IfReturnRule{},
8883
&rule.UselessBreak{},
89-
&rule.TimeEqualRule{},
9084
}, defaultRules...)
9185

9286
var allFormatters = []lint.Formatter{
@@ -133,26 +127,19 @@ func GetLintingRules(config *lint.Config) ([]lint.Rule, error) {
133127
return lintingRules, nil
134128
}
135129

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 {
140131
file, err := ioutil.ReadFile(path)
141132
if err != nil {
142-
return nil, errors.New("cannot read the config file")
133+
return errors.New("cannot read the config file")
143134
}
144135
_, err = toml.Decode(string(file), config)
145136
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)
147138
}
148-
return config, nil
139+
return nil
149140
}
150141

151142
func normalizeConfig(config *lint.Config) {
152-
if config.Confidence == math.Inf(1) {
153-
config.Confidence = defaultConfidence
154-
}
155-
156143
if len(config.Rules) == 0 {
157144
config.Rules = map[string]lint.RuleConfig{}
158145
}
@@ -186,16 +173,23 @@ func normalizeConfig(config *lint.Config) {
186173
}
187174
}
188175

176+
const defaultConfidence = 0.8
177+
189178
// GetConfig yields the configuration
190179
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)
195185
if err != nil {
196186
return nil, err
197187
}
188+
189+
default: // no configuration provided
190+
config = defaultConfig()
198191
}
192+
199193
normalizeConfig(config)
200194
return config, nil
201195
}
@@ -216,7 +210,7 @@ func GetFormatter(formatterName string) (lint.Formatter, error) {
216210

217211
func defaultConfig() *lint.Config {
218212
defaultConfig := lint.Config{
219-
Confidence: math.Inf(1),
213+
Confidence: defaultConfidence,
220214
Severity: lint.SeverityWarning,
221215
Rules: map[string]lint.RuleConfig{},
222216
}

0 commit comments

Comments
 (0)