question-mark
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.

no-extra-parens conflicts with wrap-iife

See original GitHub issue

Tell us about your environment

  • ESLint Version: 7.0.0-alpha.0
  • Node Version: v12.14.0
  • npm Version: v6.13.4

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

Configuration
module.exports = {
    parserOptions: {
        ecmaVersion: 2015
    },
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

/* eslint wrap-iife: ["error", "inside", { functionPrototypeMethods: true }] */
/* eslint no-extra-parens: ["error"] */

var x = function(){}.call(); // wrap-iife error

var x = (function(){}).call(); // no-extra-parens error

Online Demo Link (demo is v6.8.0, but it’s same)

eslint index.js --fix

What did you expect to happen?

These are two same lines, except for the parens around the function expression.

wrap-iife requires these parens, while no-extra-parens disallows them.

I’m not sure what should be expected default behavior for no-extra-parens:

This rule always ignores extra parentheses around the following:

immediately-invoked function expressions (also known as IIFEs) such as var x = (function () {})(); and ((function foo() {return 1;})()) to avoid conflicts with the wrap-iife rule

This isn’t quite an IIFE, but it is a conflict with wrap-iife.

What actually happened? Please include the actual, raw output from ESLint.

Autofix worked 10 times, so the code at the end remained unchanged, with the following errors:

  4:9  error  Wrap an immediate function invocation in parentheses  wrap-iife
  6:9  error  Unnecessary parentheses around expression             no-extra-parens

If it was set to run an odd number of times, it would basically flip those two lines.

Are you willing to submit a pull request to fix this bug?

Yes. I’m not sure should this be default or an option.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Feb 8, 2020

I’m working on this.

1reaction
mdjermanoviccommented, Feb 4, 2020

Since wrap-iife doesn’t warn on this by default, I don’t think this should be the default behavior of no-extra-parens. Thoughts on adding a corresponding option to no-extra-parens (enforceForFunctionPrototypeMethods, maybe?) that defaults to false?

Agreed! It seems better to add an option.

Only, I think it should be true by default, like all other options in this rule. true would also retain the current default behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conflicting wrap-iife and no-extra-parens for IIFE · Issue #655
Why is that a problem? wrap-iife forces the user to use parentheses that are not necessary for disambiguation or grouping.
Read more >
no-extra-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 >
Rule no-extra-parens - ESLint中文
RegExp literals such as (/abc/).test(var) to avoid conflicts with the wrap-regex rule; immediately-invokes function expressions (also known as IIFEs) such as ...
Read more >
emscripten 3.1.26-1 (x86_64) - File List
emscripten 3.1.26-1 File List. Package has 16704 files and 952 directories. Back to Package. etc/; etc/profile.d/; etc/profile.
Read more >
eslint-config-canonical
Rule CN AB GG SD XO @babel/new‑cap ❌ 👻 👻 👻 👻 @babel/no‑invalid‑this 🚨 👻 👻 👻 👻 @babel/no‑unused‑expressions 🚨 👻 👻 👻 👻
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found