no_new_object

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoNewObjectRule = rule.Rule{
	Name: "no-new-object",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindNewExpression: func(node *ast.Node) {
				callee := node.Expression()
				if callee == nil {
					return
				}

				unwrapped := ast.SkipOuterExpressions(callee, ast.OEKParentheses|ast.OEKAssertions)
				if unwrapped.Kind != ast.KindIdentifier || unwrapped.Text() != "Object" {
					return
				}

				if utils.IsShadowed(unwrapped, "Object") {
					return
				}

				ctx.ReportNode(node, rule.RuleMessage{
					Id:          "preferLiteral",
					Description: "The object literal notation {} is preferable.",
				})
			},
		}
	},
}

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