Skip to content
This repository was archived by the owner on Dec 30, 2018. It is now read-only.

Commit fd6b91e

Browse files
author
Iskander (Alex) Sharipov
authored
remove old params API usages (#25)
Signed-off-by: Iskander Sharipov <[email protected]>
1 parent f18ffd9 commit fd6b91e

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

captLocal_checker.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ func init() {
1111
var info lintpack.CheckerInfo
1212
info.Name = "captLocal"
1313
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+
}
1420
info.Summary = "Detects capitalized names for local variables"
1521
info.Before = `func f(IN int, OUT *int) (ERR error) {}`
1622
info.After = `func f(in int, out *int) (err error) {}`
1723

1824
collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker {
1925
c := &captLocalChecker{ctx: ctx}
20-
c.checkLocals = c.ctx.Params.Bool("checkLocals", true)
26+
c.paramsOnly = info.Params.Bool("paramsOnly")
2127
return astwalk.WalkerForLocalDef(c, ctx.TypesInfo)
2228
})
2329
}
@@ -27,11 +33,11 @@ type captLocalChecker struct {
2733
ctx *lintpack.CheckerContext
2834

2935
upcaseNames map[string]bool
30-
checkLocals bool
36+
paramsOnly bool
3137
}
3238

3339
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 {
3541
return
3642
}
3743
if ast.IsExported(def.ID.Name) {

checkers_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ import (
77
"github.com/go-lintpack/lintpack/linttest"
88
)
99

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+
}
1127

1228
func TestIntegration(t *testing.T) { linttest.TestIntegration(t) }
1329

elseif_checker.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ func init() {
1212
var info lintpack.CheckerInfo
1313
info.Name = "elseif"
1414
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+
}
1521
info.Summary = "Detects else with nested if statement that can be replaced with else-if"
1622
info.Before = `
1723
if cond1 {
@@ -26,7 +32,7 @@ if cond1 {
2632

2733
collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker {
2834
c := &elseifChecker{ctx: ctx}
29-
c.skipBalanced = c.ctx.Params.Bool("skipBalanced", true)
35+
c.skipBalanced = info.Params.Bool("skipBalanced")
3036
return astwalk.WalkerForStmt(c)
3137
})
3238
}

underef_checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ v := a[5]`
3030

3131
collection.AddChecker(&info, func(ctx *lintpack.CheckerContext) lintpack.FileWalker {
3232
c := &underefChecker{ctx: ctx}
33-
c.skipRecvDeref = ctx.Params.Bool("skipRecvDeref", true)
33+
c.skipRecvDeref = info.Params.Bool("skipRecvDeref")
3434
return astwalk.WalkerForExpr(c)
3535
})
3636
}

0 commit comments

Comments
 (0)