no_control_regex

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoControlRegexRule = rule.Rule{
	Name: "no-control-regex",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		report := func(node *ast.Node, controlChars []string) {
			ctx.ReportNode(node, rule.RuleMessage{
				Id:          "unexpected",
				Description: fmt.Sprintf("Unexpected control character(s) in regular expression: %s.", strings.Join(controlChars, ", ")),
			})
		}

		return rule.RuleListeners{
			ast.KindRegularExpressionLiteral: func(node *ast.Node) {
				pattern, flags := utils.ExtractRegexPatternAndFlags(node.Text())
				if chars := collectControlChars(pattern, flags); len(chars) > 0 {
					report(node, chars)
				}
			},
			ast.KindCallExpression: func(node *ast.Node) {
				callExpr := node.AsCallExpression()
				checkRegExpConstructor(callExpr.Expression, callExpr.Arguments, report)
			},
			ast.KindNewExpression: func(node *ast.Node) {
				newExpr := node.AsNewExpression()
				checkRegExpConstructor(newExpr.Expression, newExpr.Arguments, report)
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-control-regex

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