go-ruleguard
go-ruleguard copied to clipboard
match type struct declaration
Hello I'm trying to match type struct declaration. So I did:
m.Match(`type $_ struct {}`).Report("aaaa")
but it returns the error
ruleguard: load rules: parse rules file: ruleguard/rules.go:334: parse match pattern: :1: compileExpr: unexpected *ast.StructType
It's unexpected, because matching a type that uses string as base type works:
m.Match(`type $_ string`).Report("aaaa")
Do I need to use a different syntax, or is it unsupported for now ?
Thank you
PS: my final goal is to match struct declaration that contains a time.Time
field, with a omitempty
annotation.
I want to report that as an error, because time.Time
doesn't have a "zero value", so omitempty
doesn't make sense.
Per this thread https://github.com/quasilyte/go-ruleguard/issues/134, ruleguard is not really good at matching struct declarations.
Thank you for describing the final goal.
I think it should be possible to match what you need, but it should be done a little bit differently. I also need to add some way to handle struct tag strings.
I made a gogrep rewrite, so it's possible to extend the set of supported patterns eventually.