Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: wrap-iife autofix removes mandatory parentheses #12905

Merged
merged 1 commit into from Feb 28, 2020

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Feb 12, 2020

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

What is the purpose of this pull request? (put an "X" next to an item)

[X] Bug fix

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: 2020
    },
};

What did you do? Please include the actual source code causing the issue.

/*eslint wrap-iife: ["error", "inside"]*/

if (function (){}()) {}

while (function (){}()) {}

do {} while (function (){}())

switch (function (){}()) {}

with (function (){}()) {}

foo(function (){}());

new foo(function (){}());

import(function (){}());

new (function (){}())();

Online Demo Link (v6.8.0 actual)

What did you expect to happen?

Autofix to just parenthesize function expressions, without removing mandatory parentheses in constructs and necessary grouping parentheses after new.

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

Autofix:

/*eslint wrap-iife: ["error", "inside"]*/

if (function (){})() {} // syntax error

while (function (){})() {} // syntax error

do {} while (function (){})() // syntax error

switch (function (){})() {} // syntax error

with (function (){})() {} // syntax error

foo(function (){})(); // changed behavior

new foo(function (){})(); // changed behavior

import(function (){})(); // changed behavior

new (function (){})()(); // changed behavior

What changes did you make? (Give an overview)

Fixed the auto-fix to just add new parens around FunctionExpression when the existing parens around CallExpression cannot be removed.

Is there anything you'd like reviewers to focus on?

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion autofix This change is related to ESLint's autofixing capabilities labels Feb 12, 2020
Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! The comments are all very helpful and make the tests easy to understand 👍

@nzakas nzakas merged commit de14d1c into master Feb 28, 2020
@nzakas nzakas deleted the wrapiife-mandatoryparens branch February 28, 2020 01:13
montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 28, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion autofix This change is related to ESLint's autofixing capabilities bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants