Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generator for analysis.Analyzer #1

Open
tenntenn opened this issue Aug 24, 2020 · 0 comments
Open

Code generator for analysis.Analyzer #1

tenntenn opened this issue Aug 24, 2020 · 0 comments

Comments

@tenntenn
Copy link
Member

tenntenn commented Aug 24, 2020

Code generator for analysis.Analyzer from a XPath expression.
For example code generator generates the follow code from //*@type="CallExpr"]/Fn[@type="Ident" and @Name="panic"].

var Analyzer = &analysis.Analyzer{
	Name: "FIXME",
	Doc:  "FIXME",
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

func run(pass *analysis.Pass) (interface{}, error) {
	inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)

	nodeFilter := []ast.Node{
		(*ast.CallExpr)(nil),
	}

	inspect.Preorder(nodeFilter, func(n ast.Node) {
		switch n := n.(type) {
		case *ast.CallExpr:
			ident, ok := n.Fn.(*ast.Ident)
			if ok && ident.Name == "panic" {
				pass.Reportf(n.Pos(), "FIXME")
			}
		}
	})

	return nil, nil
}

XPath Parsers

@tenntenn tenntenn changed the title Generate code for analysis.Analyzer Code generator for analysis.Analyzer Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant