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

Regression on local filter functions? #310

Closed
timkral opened this issue Nov 20, 2021 · 5 comments
Closed

Regression on local filter functions? #310

timkral opened this issue Nov 20, 2021 · 5 comments

Comments

@timkral
Copy link
Contributor

timkral commented Nov 20, 2021

HI,

I'd like to use a local function as outlined in the Ruleguard by example documentation, but I encountered an error: expected a m method call, found ... . I then tried copying the exact example from the documentation and encountered the same error:

✗ ruleguard -c 1 -rules rcore/lib/linter/rules-services.go ./...
ruleguard: load rules: parse rules file: irconv error: rcore/lib/linter/rules-services.go:34: expected a m method call, found isExported := func(v dsl.Var) bool {
	return v.Text.Matches(`^\p{Lu}`)
}

Is this a feature that's still supported?

@timkral
Copy link
Contributor Author

timkral commented Nov 20, 2021

I also tried this:

// isExported reports whether bound matcher var
// represents exported Go identifier.
var isExported = func(v dsl.Var) bool {
	return v.Text.Matches(`^\p{Lu}`)
}

func exposedMutex(m dsl.Matcher) {

	// isExported() is more readable than `^\p{Lu}`
	// regular expression itself.

	m.Match(`type $name struct { $*_; sync.Mutex; $*_ }`).
		Where(isExported(m["name"])).
		Report("do not embed sync.Mutex")

	m.Match(`type $name struct { $*_; sync.RWMutex; $*_ }`).
		Where(m["name"].Text.Matches(`^\p{Lu}`)).
		Report("don not embed sync.RWMutex")
}

But got a different error:

✗ ruleguard -c 1 -rules rcore/lib/linter/rules-services.go ./...
ruleguard: load rules: parse rules file: irconv error: rcore/lib/linter/rules-services.go:34: unsupported expr: m["name"] (*ast.IndexExpr)

@quasilyte
Copy link
Owner

quasilyte commented Nov 20, 2021

Hi.
Which version are you using? Only the development branch contains this feature, I'll roll a release in the following week or two.

@timkral
Copy link
Contributor Author

timkral commented Nov 20, 2021

Hi @quasilyte ,

Got it, thanks for the response. I'm using version v0.3.13. Ultimately, I'd like to use the feature in the golangci-lint tool so I will wait for a new release and version upgrade there.

-Tim

@timkral timkral closed this as completed Nov 20, 2021
@timkral
Copy link
Contributor Author

timkral commented Dec 22, 2021

Hi @quasilyte ,

I was wondering if there was any updates on releasing a new version to include these changes.

Thanks.
-Tim

@quasilyte
Copy link
Owner

I would like to investigate and fix #317 if it's reproducible.
After that, a new release can be made.
I could try poking at that issue this weekend.

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

2 participants