Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disallow new with empty parens

See original GitHub issue

The rule can be implemented as one of the following:

  • an option in new-parens rule
  • an option in no-extra-parens rule
  • a separate rule

When does this rule warn? Please describe and show example code:

var p = new Person(); // error
var p = new Person; // correct
var name = new Person().getName(); // optionally correct

Is this rule preventing an error or is it stylistic?


Why is this rule a candidate for inclusion instead of creating a custom rule?

It is generic

Are you willing to create the rule yourself?


Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

btmillscommented, Aug 21, 2016

@platinumazure good catch, that’s quite the wrench. Let’s see… Based on the cases demonstrated below, it looks like we’ll need either a tri-state or an option on the “never”. I agree with @epoberezkin that immediate property access is pretty ugly, so maybe there’s a way to support that too.

/* 1 */ new Class()
/* 2 */ new Class.staticPropertyReturningConstructor()
/* 3 */ new Class().instanceProperty
/* 4 */ new Class().instanceMethod()
/* 5 */ new Class
/* 6 */ new Class.staticPropertyReturningConstructor
/* 7 */ (new Class).instanceProperty
/* 8 */ (new Class).instanceMethod()

So what if we started off with “always” (1-4 valid) and “never” (5-8 valid). Then, later, if someone requests an option that makes 3-6 valid, we could add a third state, making it “always”/“never”/“chained” or something like that.

btmillscommented, Aug 16, 2016

What about adding an “always” (default) / “never” mode to new-parens?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can we omit parentheses when creating an object using the ...
As a special case, for the new operator only, JavaScript simplifies the grammar by allowing the parenthesis to be omitted if there are...
Read more >
space-in-parens - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Remove parentheses for empty year field biblatex ieee style
By using biblatex ieee style, I found that the reference will display empty brackets even though the field "year" ...
Read more >
What is the significance of empty parentheses? - Codecademy
VariableName+() is a function call and empty () mean that you don't use parameters ... Let's assume your function requires no parameter but...
Read more >
Parentheses are redundant if attribute has no arguments
If an attribute's constructor has no parameters, C# allows you to specify it without parentheses when you call it. ReSharper suggests removing  ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found