This repository was archived by the owner on Dec 30, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +34
-6
lines changed Expand file tree Collapse file tree 4 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,19 @@ func init() {
11
11
var info lintpack.CheckerInfo
12
12
info .Name = "captLocal"
13
13
info .Tags = []string {"style" }
14
+ info .Params = lintpack.CheckerParams {
15
+ "paramsOnly" : {
16
+ Value : true ,
17
+ Usage : "whether to restrict checker to params only" ,
18
+ },
19
+ }
14
20
info .Summary = "Detects capitalized names for local variables"
15
21
info .Before = `func f(IN int, OUT *int) (ERR error) {}`
16
22
info .After = `func f(in int, out *int) (err error) {}`
17
23
18
24
collection .AddChecker (& info , func (ctx * lintpack.CheckerContext ) lintpack.FileWalker {
19
25
c := & captLocalChecker {ctx : ctx }
20
- c .checkLocals = c . ctx . Params .Bool ("checkLocals" , true )
26
+ c .paramsOnly = info . Params .Bool ("paramsOnly" )
21
27
return astwalk .WalkerForLocalDef (c , ctx .TypesInfo )
22
28
})
23
29
}
@@ -27,11 +33,11 @@ type captLocalChecker struct {
27
33
ctx * lintpack.CheckerContext
28
34
29
35
upcaseNames map [string ]bool
30
- checkLocals bool
36
+ paramsOnly bool
31
37
}
32
38
33
39
func (c * captLocalChecker ) VisitLocalDef (def astwalk.Name , _ ast.Expr ) {
34
- if ! c . checkLocals && def .Kind != astwalk .NameParam {
40
+ if c . paramsOnly && def .Kind != astwalk .NameParam {
35
41
return
36
42
}
37
43
if ast .IsExported (def .ID .Name ) {
Original file line number Diff line number Diff line change @@ -7,7 +7,23 @@ import (
7
7
"github.com/go-lintpack/lintpack/linttest"
8
8
)
9
9
10
- func TestCheckers (t * testing.T ) { linttest .TestCheckers (t ) }
10
+ func TestCheckers (t * testing.T ) {
11
+ allParams := map [string ]map [string ]interface {}{
12
+ "captLocal" : {"paramsOnly" : false },
13
+ }
14
+
15
+ for _ , info := range lintpack .GetCheckersInfo () {
16
+ params := allParams [info .Name ]
17
+ for key , p := range info .Params {
18
+ v , ok := params [key ]
19
+ if ok {
20
+ p .Value = v
21
+ }
22
+ }
23
+ }
24
+
25
+ linttest .TestCheckers (t )
26
+ }
11
27
12
28
func TestIntegration (t * testing.T ) { linttest .TestIntegration (t ) }
13
29
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ func init() {
12
12
var info lintpack.CheckerInfo
13
13
info .Name = "elseif"
14
14
info .Tags = []string {"style" }
15
+ info .Params = lintpack.CheckerParams {
16
+ "skipBalanced" : {
17
+ Value : true ,
18
+ Usage : "whether to skip balanced if-else pairs" ,
19
+ },
20
+ }
15
21
info .Summary = "Detects else with nested if statement that can be replaced with else-if"
16
22
info .Before = `
17
23
if cond1 {
@@ -26,7 +32,7 @@ if cond1 {
26
32
27
33
collection .AddChecker (& info , func (ctx * lintpack.CheckerContext ) lintpack.FileWalker {
28
34
c := & elseifChecker {ctx : ctx }
29
- c .skipBalanced = c . ctx . Params .Bool ("skipBalanced" , true )
35
+ c .skipBalanced = info . Params .Bool ("skipBalanced" )
30
36
return astwalk .WalkerForStmt (c )
31
37
})
32
38
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ v := a[5]`
30
30
31
31
collection .AddChecker (& info , func (ctx * lintpack.CheckerContext ) lintpack.FileWalker {
32
32
c := & underefChecker {ctx : ctx }
33
- c .skipRecvDeref = ctx .Params .Bool ("skipRecvDeref" , true )
33
+ c .skipRecvDeref = info .Params .Bool ("skipRecvDeref" )
34
34
return astwalk .WalkerForExpr (c )
35
35
})
36
36
}
You can’t perform that action at this time.
0 commit comments