Skip to content

Commit 5e6be15

Browse files
committed
Add varcheck
1 parent 4a392eb commit 5e6be15

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

varcheck/varcheck.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Package varcheck provides lint integration for the varcheck linter
2+
package varcheck
3+
4+
import "github.com/surullabs/lint/checkers"
5+
6+
// Check runs the varcheck linter (https://github.com/opennota/check)
7+
type Check struct {
8+
// ReportExported reports exported variables that are unused
9+
ReportExported bool
10+
}
11+
12+
// Check runs varcheck and returns any errors found.
13+
func (c Check) Check(pkgs ...string) error {
14+
var args []string
15+
if c.ReportExported {
16+
args = append(args, "-e")
17+
}
18+
return checkers.Lint("varcheck", "github.com/opennota/check/cmd/varcheck", pkgs, args...)
19+
}

varcheck/varcheck_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package varcheck_test
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/surullabs/lint"
8+
"github.com/surullabs/lint/varcheck"
9+
"github.com/surullabs/lint/testutil"
10+
)
11+
12+
func TestGoVarcheck(t *testing.T) {
13+
testutil.Test(t, "varchecktest", []testutil.StaticCheckTest{
14+
{
15+
Checker: varcheck.Check{},
16+
Content: []byte(`package varchecktest
17+
// TestFunc is a test function
18+
func TestFunc() {
19+
}
20+
`),
21+
Validate: testutil.NoError,
22+
},
23+
{
24+
Checker: varcheck.Check{},
25+
Content: []byte(`package varchecktest
26+
sfsff
27+
28+
func TestFunc() {
29+
}
30+
`),
31+
Validate: testutil.Contains("expected declaration, found 'IDENT' sfsff"),
32+
},
33+
{
34+
Checker: varcheck.Check{},
35+
Content: []byte(`package varchecktest
36+
var unused bool
37+
`),
38+
Validate: testutil.HasSuffix("unused"),
39+
},
40+
{
41+
Checker: lint.Skip(varcheck.Check{}, lint.StringSkipper{
42+
Strings: []string{
43+
"unused",
44+
},
45+
Matcher: strings.HasSuffix,
46+
}),
47+
Content: []byte(`package varchecktest
48+
49+
var unused bool
50+
`),
51+
Validate: testutil.NoError,
52+
},
53+
},
54+
)
55+
}

0 commit comments

Comments
 (0)