File tree 4 files changed +63
-16
lines changed
4 files changed +63
-16
lines changed Original file line number Diff line number Diff line change 6
6
"fmt"
7
7
"go/token"
8
8
"io/ioutil"
9
+ "reflect"
9
10
10
11
"github.com/BurntSushi/toml"
11
12
"github.com/mgechev/dots"
@@ -136,20 +137,22 @@ func NewRevive(cfg *config.ReviveSettings) *goanalysis.Linter {
136
137
// https://github.com/golangci/golangci-lint/issues/1745
137
138
// https://github.com/mgechev/revive/blob/389ba853b0b3587f0c3b71b5f0c61ea4e23928ec/config/config.go#L155
138
139
func getReviveConfig (cfg * config.ReviveSettings ) (* lint.Config , error ) {
139
- rawRoot := createConfigMap (cfg )
140
-
141
- buf := bytes .NewBuffer (nil )
140
+ conf := defaultConfig ()
142
141
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 )
147
145
148
- conf := defaultConfig ()
146
+ err := toml .NewEncoder (buf ).Encode (rawRoot )
147
+ if err != nil {
148
+ return nil , err
149
+ }
149
150
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
+ }
153
156
}
154
157
155
158
normalizeConfig (conf )
Original file line number Diff line number Diff line change @@ -3,12 +3,10 @@ linters-settings:
3
3
ignore-generated-header : true
4
4
severity : warning
5
5
rules :
6
- - name : indent-error-flow
7
- severity : warning
8
6
- name : cognitive-complexity
9
7
arguments : [ 7 ]
10
8
- name : line-length-limit
11
- arguments : [ 110 ]
9
+ arguments : [ 130 ]
12
10
- name : function-result-limit
13
11
arguments : [ 3 ]
14
12
- name : argument-limit
Original file line number Diff line number Diff line change 2
2
//config_path: testdata/configs/revive.yml
3
3
package testdata
4
4
5
- import "time"
5
+ import (
6
+ "net/http"
7
+ "time"
8
+ )
6
9
7
10
func testRevive (t * time.Duration ) error {
8
11
if t == nil {
9
12
return nil
10
- } else { // ERROR "indent-error-flow: if block ends with a return statement, .*"
13
+ } else {
11
14
return nil
12
15
}
13
16
}
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