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

Loop and Configuration #464

Open
maranqz opened this issue Oct 22, 2023 · 1 comment
Open

Loop and Configuration #464

maranqz opened this issue Oct 22, 2023 · 1 comment

Comments

@maranqz
Copy link

maranqz commented Oct 22, 2023

Hello,

I created linter, and I want to have ability to change list of packages (m.Import) without changing the code.
Could I do it, are there planes to implement?
That help to config and set custom settings.

package write

import (
	"strings"

	"github.com/quasilyte/go-ruleguard/dsl"
	"github.com/quasilyte/go-ruleguard/dsl/types"
)

// https://github.com/quasilyte/go-ruleguard/blob/master/_docs/dsl.md#creating-a-ruleguard-bundle
var Bundle = dsl.Bundle{}

func factory(m dsl.Matcher) {
	m.Import("ddd/testdata/src/write/nested")
	m.Import("ddd/testdata/src/write/nested/nested2")

	m.Match("$x.$field = $_", "$x.$field++").
		//Where(m["x"].Filter(isWrite)).
		//Report(`$x.$field is readonly`)
		Do(report)
}

func report(ctx *dsl.DoContext) {
	typX := ctx.Var("x").Type()

	asPointer := types.AsPointer(typX)
	if asPointer != nil {
		typX = asPointer.Elem()
	}

	if strings.HasPrefix(typX.String(), "ddd/testdata/src/write/nested.") ||
		strings.HasPrefix(typX.String(), "ddd/testdata/src/write/nested/nested2.") {
		field := ctx.Var("field")

		ctx.SetReport(typX.String() + "." + field.Text())
	}

}
@quasilyte
Copy link
Owner

Hmm.
The only thing that comes to my mind is binding the values at the command line.
Like running the ruleguard with named values specified to substitute variables in the rules file.
Something akin to the way we can bind Go constants with a linker.

Any other ideas?

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