Skip to content

Loop and Configuration #464

@maranqz

Description

@maranqz

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions