no_restricted_syntax

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoRestrictedSyntaxRule = rule.Rule{
	Name: "no-restricted-syntax",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		entries := parseRuleOptions(options)
		if len(entries) == 0 {
			return rule.RuleListeners{}
		}

		mc := &matchContext{sf: ctx.SourceFile}

		perKind := make(map[ast.Kind][]ruleEntry)
		var everyKind []ruleEntry
		for _, e := range entries {
			ks := candidateKinds(e.compiled)
			if ks.universe {
				everyKind = append(everyKind, e)
				continue
			}
			for k := range ks.kinds {
				perKind[k] = append(perKind[k], e)
			}
		}

		if len(everyKind) > 0 {
			for _, k := range allInterestingKinds {
				perKind[k] = append(perKind[k], everyKind...)
			}
		}

		visit := func(node *ast.Node, bucket []ruleEntry) {
			for _, e := range bucket {
				if matches(e.compiled, node, mc) {
					ctx.ReportNode(node, rule.RuleMessage{
						Id:          "restrictedSyntax",
						Description: e.formatMessage(),
					})
				}
			}
		}

		listeners := rule.RuleListeners{}
		for k, bucket := range perKind {
			listeners[k] = func(node *ast.Node) {
				visit(node, bucket)
			}
		}
		return listeners
	},
}

NoRestrictedSyntaxRule is the rslint port of ESLint's `no-restricted-syntax`.

Configuration mirrors ESLint: the rule accepts a list of strings or `{ selector, message? }` objects. Each selector follows the esquery grammar (the subset implemented in parser.go). At lint time every node is matched against every parsed selector; each match produces one diagnostic with the user-supplied message (or a default).

https://eslint.org/docs/latest/rules/no-restricted-syntax

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL