mirror of
https://github.com/mgechev/revive.git
synced 2025-03-19 21:07:46 +02:00
Update config.go
removes use of `math.Inf(1)`
This commit is contained in:
parent
c3af594461
commit
12e4e8c172
@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/mgechev/revive/formatter"
|
"github.com/mgechev/revive/formatter"
|
||||||
|
|
||||||
@ -13,10 +12,6 @@ import (
|
|||||||
"github.com/mgechev/revive/rule"
|
"github.com/mgechev/revive/rule"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
defaultConfidence = 0.8
|
|
||||||
)
|
|
||||||
|
|
||||||
var defaultRules = []lint.Rule{
|
var defaultRules = []lint.Rule{
|
||||||
&rule.VarDeclarationsRule{},
|
&rule.VarDeclarationsRule{},
|
||||||
&rule.PackageCommentsRule{},
|
&rule.PackageCommentsRule{},
|
||||||
@ -86,7 +81,6 @@ var allRules = append([]lint.Rule{
|
|||||||
&rule.NestedStructs{},
|
&rule.NestedStructs{},
|
||||||
&rule.IfReturnRule{},
|
&rule.IfReturnRule{},
|
||||||
&rule.UselessBreak{},
|
&rule.UselessBreak{},
|
||||||
&rule.TimeEqualRule{},
|
|
||||||
}, defaultRules...)
|
}, defaultRules...)
|
||||||
|
|
||||||
var allFormatters = []lint.Formatter{
|
var allFormatters = []lint.Formatter{
|
||||||
@ -133,26 +127,19 @@ func GetLintingRules(config *lint.Config) ([]lint.Rule, error) {
|
|||||||
return lintingRules, nil
|
return lintingRules, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfig(path string) (*lint.Config, error) {
|
func parseConfig(path string, config *lint.Config) error {
|
||||||
config := &lint.Config{
|
|
||||||
Confidence: math.Inf(1),
|
|
||||||
}
|
|
||||||
file, err := ioutil.ReadFile(path)
|
file, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("cannot read the config file")
|
return errors.New("cannot read the config file")
|
||||||
}
|
}
|
||||||
_, err = toml.Decode(string(file), config)
|
_, err = toml.Decode(string(file), config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot parse the config file: %v", err)
|
return fmt.Errorf("cannot parse the config file: %v", err)
|
||||||
}
|
}
|
||||||
return config, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeConfig(config *lint.Config) {
|
func normalizeConfig(config *lint.Config) {
|
||||||
if config.Confidence == math.Inf(1) {
|
|
||||||
config.Confidence = defaultConfidence
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(config.Rules) == 0 {
|
if len(config.Rules) == 0 {
|
||||||
config.Rules = map[string]lint.RuleConfig{}
|
config.Rules = map[string]lint.RuleConfig{}
|
||||||
}
|
}
|
||||||
@ -186,16 +173,23 @@ func normalizeConfig(config *lint.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultConfidence = 0.8
|
||||||
|
|
||||||
// GetConfig yields the configuration
|
// GetConfig yields the configuration
|
||||||
func GetConfig(configPath string) (*lint.Config, error) {
|
func GetConfig(configPath string) (*lint.Config, error) {
|
||||||
config := defaultConfig()
|
var config = &lint.Config{}
|
||||||
if configPath != "" {
|
switch {
|
||||||
var err error
|
case configPath != "":
|
||||||
config, err = parseConfig(configPath)
|
config.Confidence = defaultConfidence
|
||||||
|
err := parseConfig(configPath, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default: // no configuration provided
|
||||||
|
config = defaultConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizeConfig(config)
|
normalizeConfig(config)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
@ -216,7 +210,7 @@ func GetFormatter(formatterName string) (lint.Formatter, error) {
|
|||||||
|
|
||||||
func defaultConfig() *lint.Config {
|
func defaultConfig() *lint.Config {
|
||||||
defaultConfig := lint.Config{
|
defaultConfig := lint.Config{
|
||||||
Confidence: math.Inf(1),
|
Confidence: defaultConfidence,
|
||||||
Severity: lint.SeverityWarning,
|
Severity: lint.SeverityWarning,
|
||||||
Rules: map[string]lint.RuleConfig{},
|
Rules: map[string]lint.RuleConfig{},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user