-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
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())
}
}
Metadata
Metadata
Assignees
Labels
No labels