Skip to content

Commit

Permalink
Add varcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
sridharv committed Nov 5, 2016
1 parent 4a392eb commit 5e6be15
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions varcheck/varcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Package varcheck provides lint integration for the varcheck linter
package varcheck

import "github.com/surullabs/lint/checkers"

// Check runs the varcheck linter (https://github.com/opennota/check)
type Check struct {
// ReportExported reports exported variables that are unused
ReportExported bool
}

// Check runs varcheck and returns any errors found.
func (c Check) Check(pkgs ...string) error {
var args []string
if c.ReportExported {
args = append(args, "-e")
}
return checkers.Lint("varcheck", "github.com/opennota/check/cmd/varcheck", pkgs, args...)
}
55 changes: 55 additions & 0 deletions varcheck/varcheck_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package varcheck_test

import (
"strings"
"testing"

"github.com/surullabs/lint"
"github.com/surullabs/lint/varcheck"
"github.com/surullabs/lint/testutil"
)

func TestGoVarcheck(t *testing.T) {
testutil.Test(t, "varchecktest", []testutil.StaticCheckTest{
{
Checker: varcheck.Check{},
Content: []byte(`package varchecktest
// TestFunc is a test function
func TestFunc() {
}
`),
Validate: testutil.NoError,
},
{
Checker: varcheck.Check{},
Content: []byte(`package varchecktest
sfsff
func TestFunc() {
}
`),
Validate: testutil.Contains("expected declaration, found 'IDENT' sfsff"),
},
{
Checker: varcheck.Check{},
Content: []byte(`package varchecktest
var unused bool
`),
Validate: testutil.HasSuffix("unused"),
},
{
Checker: lint.Skip(varcheck.Check{}, lint.StringSkipper{
Strings: []string{
"unused",
},
Matcher: strings.HasSuffix,
}),
Content: []byte(`package varchecktest
var unused bool
`),
Validate: testutil.NoError,
},
},
)
}

0 comments on commit 5e6be15

Please sign in to comment.