no_new

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: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoNewRule = rule.Rule{
	Name: "no-new",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindExpressionStatement: func(node *ast.Node) {
				stmt := node.AsExpressionStatement()
				if stmt == nil {
					return
				}
				expr := ast.SkipParentheses(stmt.Expression)
				if expr == nil || expr.Kind != ast.KindNewExpression {
					return
				}
				ctx.ReportNode(node, rule.RuleMessage{
					Id:          "noNewStatement",
					Description: "Do not use 'new' for side effects.",
				})
			},
		}
	},
}

https://eslint.org/docs/latest/rules/no-new

ESLint's selector `ExpressionStatement > NewExpression` relies on ESTree stripping parentheses from the AST. tsgo keeps `ParenthesizedExpression` nodes, so walk through them with `ast.SkipParentheses` to match ESLint on forms like `(new Foo());`.

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