Skip to content

Commit

Permalink
Merge pull request #4 from gostaticanalysis/fix-template
Browse files Browse the repository at this point in the history
Fix templates
  • Loading branch information
tenntenn authored Mar 10, 2020
2 parents 1b7d036 + d7c9acf commit 513a933
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
const doc = "{{.Pkg}} is ..."
// Analyzer is ...
var Analyzer = &analysis.Analyzer{
Name: "{{.Pkg}}",
Doc: Doc,
Doc: doc,
Run: run,
Requires: []*analysis.Analyzer{
inspect.Analyzer,
},
}
const Doc = "{{.Pkg}} is ..."
func run(pass *analysis.Pass) (interface{}, error) {
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
Expand All @@ -33,7 +34,9 @@ func run(pass *analysis.Pass) (interface{}, error) {
inspect.Preorder(nodeFilter, func(n ast.Node) {
switch n := n.(type) {
case *ast.Ident:
_ = n
if n.Name == "gopher" {
pass.Reportf(n.Pos(), "identifyer is gopher")
}
}
})
Expand All @@ -50,16 +53,19 @@ import (
"golang.org/x/tools/go/analysis/analysistest"
)
func Test(t *testing.T) {
// TestAnalyzer is a test for Analyzer.
func TestAnalyzer(t *testing.T) {
testdata := analysistest.TestData()
analysistest.Run(t, testdata, {{.Pkg}}.Analyzer, "a")
}
`))

var adotgoTempl = template.Must(template.New("a.go").Parse(`package a
func main() {
// want "pattern"
func f() {
// The pattern can be written in regular expression.
var gopher int // want "pattern"
print(gopher) // want "identifyer is gopher"
}
`))

Expand Down

0 comments on commit 513a933

Please sign in to comment.