revive: the default configuration is only applied when no dedicated configuration. (#1831)
This commit is contained in:
parent
e381b33092
commit
cd6644d47b
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/mgechev/dots"
|
"github.com/mgechev/dots"
|
||||||
@ -136,8 +137,10 @@ func NewRevive(cfg *config.ReviveSettings) *goanalysis.Linter {
|
|||||||
// https://github.com/golangci/golangci-lint/issues/1745
|
// https://github.com/golangci/golangci-lint/issues/1745
|
||||||
// https://github.com/mgechev/revive/blob/389ba853b0b3587f0c3b71b5f0c61ea4e23928ec/config/config.go#L155
|
// https://github.com/mgechev/revive/blob/389ba853b0b3587f0c3b71b5f0c61ea4e23928ec/config/config.go#L155
|
||||||
func getReviveConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
|
func getReviveConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
|
||||||
rawRoot := createConfigMap(cfg)
|
conf := defaultConfig()
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(cfg, &config.ReviveSettings{}) {
|
||||||
|
rawRoot := createConfigMap(cfg)
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
err := toml.NewEncoder(buf).Encode(rawRoot)
|
err := toml.NewEncoder(buf).Encode(rawRoot)
|
||||||
@ -145,12 +148,12 @@ func getReviveConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := defaultConfig()
|
conf = &lint.Config{}
|
||||||
|
|
||||||
_, err = toml.DecodeReader(buf, conf)
|
_, err = toml.DecodeReader(buf, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
normalizeConfig(conf)
|
normalizeConfig(conf)
|
||||||
|
|
||||||
|
4
test/testdata/configs/revive.yml
vendored
4
test/testdata/configs/revive.yml
vendored
@ -3,12 +3,10 @@ linters-settings:
|
|||||||
ignore-generated-header: true
|
ignore-generated-header: true
|
||||||
severity: warning
|
severity: warning
|
||||||
rules:
|
rules:
|
||||||
- name: indent-error-flow
|
|
||||||
severity: warning
|
|
||||||
- name: cognitive-complexity
|
- name: cognitive-complexity
|
||||||
arguments: [ 7 ]
|
arguments: [ 7 ]
|
||||||
- name: line-length-limit
|
- name: line-length-limit
|
||||||
arguments: [ 110 ]
|
arguments: [ 130 ]
|
||||||
- name: function-result-limit
|
- name: function-result-limit
|
||||||
arguments: [ 3 ]
|
arguments: [ 3 ]
|
||||||
- name: argument-limit
|
- name: argument-limit
|
||||||
|
21
test/testdata/revive.go
vendored
21
test/testdata/revive.go
vendored
@ -2,12 +2,29 @@
|
|||||||
//config_path: testdata/configs/revive.yml
|
//config_path: testdata/configs/revive.yml
|
||||||
package testdata
|
package testdata
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
func testRevive(t *time.Duration) error {
|
func testRevive(t *time.Duration) error {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil
|
return nil
|
||||||
} else { // ERROR "indent-error-flow: if block ends with a return statement, .*"
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testReviveComplexity(s string) { // ERROR "cyclomatic: function testReviveComplexity has cyclomatic complexity 22"
|
||||||
|
if s == http.MethodGet || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
29
test/testdata/revive_default.go
vendored
Normal file
29
test/testdata/revive_default.go
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//args: -Erevive
|
||||||
|
package testdata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func testReviveDefault(t *time.Duration) error {
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
} else { // ERROR "indent-error-flow: if block ends with a return statement, .*"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testReviveComplexityDefault(s string) {
|
||||||
|
if s == http.MethodGet || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user