-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
) | ||
} |