Skip to content

Latest commit

 

History

History
80 lines (50 loc) · 1.68 KB

new-parens.md

File metadata and controls

80 lines (50 loc) · 1.68 KB
title rule_type
new-parens
layout

This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js.

JavaScript allows the omission of parentheses when invoking a function via the new keyword and the constructor has no arguments. However, some coders believe that omitting the parentheses is inconsistent with the rest of the language and thus makes code less clear.

var person = new Person;

Rule Details

This rule can enforce or disallow parentheses when invoking a constructor with no arguments using the new keyword.

Options

This rule takes one option.

  • "always" enforces parenthesis after a new constructor with no arguments (default)
  • "never" enforces no parenthesis after a new constructor with no arguments

always

Examples of incorrect code for this rule with the "always" option:

::: incorrect

/*eslint new-parens: "error"*/

var person = new Person;
var person = new (Person);

:::

Examples of correct code for this rule with the "always" option:

::: correct

/*eslint new-parens: "error"*/

var person = new Person();
var person = new (Person)();

:::

never

Examples of incorrect code for this rule with the "never" option:

::: incorrect

/*eslint new-parens: ["error", "never"]*/

var person = new Person();
var person = new (Person)();

:::

Examples of correct code for this rule with the "never" option:

::: correct

/*eslint new-parens: ["error", "never"]*/

var person = new Person;
var person = (new Person);
var person = new Person("Name");

:::