go-ruleguard icon indicating copy to clipboard operation
go-ruleguard copied to clipboard

match type struct declaration

Open pierrre opened this issue 3 years ago • 2 comments

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.

pierrre avatar Jun 22 '21 08:06 pierrre

Per this thread https://github.com/quasilyte/go-ruleguard/issues/134, ruleguard is not really good at matching struct declarations.

mislav avatar Jul 28 '21 11:07 mislav

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.

quasilyte avatar Aug 16 '21 06:08 quasilyte