File tree Expand file tree Collapse file tree 4 files changed +63
-16
lines changed
Expand file tree Collapse file tree 4 files changed +63
-16
lines changed Original file line number Diff line number Diff line change 66 "fmt"
77 "go/token"
88 "io/ioutil"
9+ "reflect"
910
1011 "github.com/BurntSushi/toml"
1112 "github.com/mgechev/dots"
@@ -136,20 +137,22 @@ func NewRevive(cfg *config.ReviveSettings) *goanalysis.Linter {
136137// https://github.com/golangci/golangci-lint/issues/1745
137138// https://github.com/mgechev/revive/blob/389ba853b0b3587f0c3b71b5f0c61ea4e23928ec/config/config.go#L155
138139func getReviveConfig (cfg * config.ReviveSettings ) (* lint.Config , error ) {
139- rawRoot := createConfigMap (cfg )
140-
141- buf := bytes .NewBuffer (nil )
140+ conf := defaultConfig ()
142141
143- err := toml .NewEncoder (buf ).Encode (rawRoot )
144- if err != nil {
145- return nil , err
146- }
142+ if ! reflect .DeepEqual (cfg , & config.ReviveSettings {}) {
143+ rawRoot := createConfigMap (cfg )
144+ buf := bytes .NewBuffer (nil )
147145
148- conf := defaultConfig ()
146+ err := toml .NewEncoder (buf ).Encode (rawRoot )
147+ if err != nil {
148+ return nil , err
149+ }
149150
150- _ , err = toml .DecodeReader (buf , conf )
151- if err != nil {
152- return nil , err
151+ conf = & lint.Config {}
152+ _ , err = toml .DecodeReader (buf , conf )
153+ if err != nil {
154+ return nil , err
155+ }
153156 }
154157
155158 normalizeConfig (conf )
Original file line number Diff line number Diff line change @@ -3,12 +3,10 @@ linters-settings:
33 ignore-generated-header : true
44 severity : warning
55 rules :
6- - name : indent-error-flow
7- severity : warning
86 - name : cognitive-complexity
97 arguments : [ 7 ]
108 - name : line-length-limit
11- arguments : [ 110 ]
9+ arguments : [ 130 ]
1210 - name : function-result-limit
1311 arguments : [ 3 ]
1412 - name : argument-limit
Original file line number Diff line number Diff line change 22//config_path: testdata/configs/revive.yml
33package testdata
44
5- import "time"
5+ import (
6+ "net/http"
7+ "time"
8+ )
69
710func testRevive (t * time.Duration ) error {
811 if t == nil {
912 return nil
10- } else { // ERROR "indent-error-flow: if block ends with a return statement, .*"
13+ } else {
1114 return nil
1215 }
1316}
17+
18+ func testReviveComplexity (s string ) { // ERROR "cyclomatic: function testReviveComplexity has cyclomatic complexity 22"
19+ if s == http .MethodGet || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
20+ return
21+ }
22+
23+ if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
24+ return
25+ }
26+
27+ if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
28+ return
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ //args: -Erevive
2+ package testdata
3+
4+ import (
5+ "net/http"
6+ "time"
7+ )
8+
9+ func testReviveDefault (t * time.Duration ) error {
10+ if t == nil {
11+ return nil
12+ } else { // ERROR "indent-error-flow: if block ends with a return statement, .*"
13+ return nil
14+ }
15+ }
16+
17+ func testReviveComplexityDefault (s string ) {
18+ if s == http .MethodGet || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
19+ return
20+ }
21+
22+ if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
23+ return
24+ }
25+
26+ if s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" {
27+ return
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments