Skip to content

Commit

Permalink
nit: include _test.go files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioCarrion committed Jun 12, 2019
1 parent 8111de3 commit d90e955
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
29 changes: 20 additions & 9 deletions cmd/nit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"go/build"
"os"
"path/filepath"
"strings"

"github.com/MarioCarrion/nit"
)
Expand All @@ -28,6 +29,7 @@ func main() {

localPkg := flag.String("pkg", "", "local package")
skipGenerated := flag.Bool("skip-generated", false, "skip generated files")
includeTests := flag.Bool("include-tests", false, "include test files")
showVersion := flag.Bool("version", false, "prints current version information")

flag.Parse()
Expand All @@ -45,26 +47,35 @@ func main() {

var failed bool

for _, pkg := range flag.Args() {
p, err := build.Import(pkg, ".", 0)
if err != nil {
fmt.Printf("error importing %s\n", pkg)
os.Exit(1)
}
nitpick := func(files []string) {
for _, f := range files {
if strings.HasSuffix(f, "_test.go") && !*includeTests {
continue
}

for _, f := range p.GoFiles {
fullpath := filepath.Join(p.Dir, f)
v := nit.Nitpicker{
LocalPath: *localPkg,
SkipGeneratedFile: *skipGenerated,
}
if err := v.Validate(fullpath); err != nil {

if err := v.Validate(f); err != nil {
failed = true
fmt.Println(err)
}
}
}

for _, pkg := range flag.Args() {
p, err := build.Import(pkg, ".", 0)
if err != nil {
fmt.Printf("error importing %s\n", pkg)
os.Exit(1)
}

gofiles, _ := filepath.Glob(filepath.Join(p.Dir, "*.go"))
nitpick(gofiles)
}

if failed {
os.Exit(1)
}
Expand Down
2 changes: 2 additions & 0 deletions file_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func TestNewFileSectionTransition(t *testing.T) {
}
}

//-

func TestFileSectionMachine(t *testing.T) {
s := nit.FileSectionMachine{}

Expand Down
6 changes: 6 additions & 0 deletions imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func TestNewImportsSection(t *testing.T) {
}
}

//-

//nolint:dupl
func TestImportsValidator(t *testing.T) {
tests := [...]struct {
Expand Down Expand Up @@ -98,6 +100,8 @@ func TestImportsValidator(t *testing.T) {
}
}

//-

func TestNewImportsTransition(t *testing.T) {
tests := [...]struct {
name string
Expand Down Expand Up @@ -136,6 +140,8 @@ func TestNewImportsTransition(t *testing.T) {
}
}

//-

func TestImportsTransitionExternal(t *testing.T) {
i, _ := nit.NewImportsTransition(nit.ImportsSectionExternal)

Expand Down
1 change: 0 additions & 1 deletion nitpicking.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (v *Nitpicker) Validate(filename string) error {
}

for _, s := range f.Decls {
// fmt.Printf("%d == %T - %+v -- %t\n", v.fset.PositionFor(s.Pos(), false).Line, s, s, s.End().IsValid())
if err := v.validateToken(s); err != nil {
return err
}
Expand Down

0 comments on commit d90e955

Please sign in to comment.