-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from gostaticanalysis/add-pkg
Add zapvet package
- Loading branch information
Showing
6 changed files
with
93 additions
and
6 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
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gostaticanalysis/zapvet/passes/fieldtype" | ||
"github.com/gostaticanalysis/zapvet/zapvet" | ||
"golang.org/x/tools/go/analysis/unitchecker" | ||
) | ||
|
||
func main() { unitchecker.Main(fieldtype.Analyzer) } | ||
func main() { unitchecker.Main(zapvet.Analyzers()...) } |
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
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,13 @@ | ||
package zapvet | ||
|
||
import ( | ||
"github.com/gostaticanalysis/zapvet/passes/fieldtype" | ||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
// Analyzers returns analyzers of zapvet. | ||
func Analyzers() []*analysis.Analyzer { | ||
return []*analysis.Analyzer{ | ||
fieldtype.Analyzer, | ||
} | ||
} |
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,37 @@ | ||
package zapvet_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/gostaticanalysis/zapvet/zapvet" | ||
"golang.org/x/tools/go/packages" | ||
) | ||
|
||
func TestAnalyzers(t *testing.T) { | ||
want := analyzerNames(t) | ||
got := zapvet.Analyzers() | ||
gotNames := make([]string, len(got)) | ||
for i := range got { | ||
gotNames[i] = got[i].Name | ||
} | ||
if diff := cmp.Diff(want, gotNames); diff != "" { | ||
t.Error(diff) | ||
} | ||
} | ||
|
||
func analyzerNames(t *testing.T) []string { | ||
t.Helper() | ||
cfg := &packages.Config{Mode: packages.NeedName} | ||
pkgs, err := packages.Load(cfg, "github.com/gostaticanalysis/zapvet/passes/...") | ||
if err != nil { | ||
t.Fatal("unexpected error:", err) | ||
} | ||
|
||
names := make([]string, len(pkgs)) | ||
for i := range pkgs { | ||
names[i] = pkgs[i].Name | ||
} | ||
|
||
return names | ||
} |