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

Update: add fixer for operator-assignment #7517

Merged
merged 1 commit into from Nov 25, 2016
Merged

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Nov 2, 2016

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

[x] Add autofixing to a rule

What changes did you make? (Give an overview)

This adds a fixer for operator-assignment.

/* eslint operator-assignment: error */

foo.bar = foo.bar + baz;

// gets fixed to:

foo.bar += baz;
/* eslint operator-assignment: [error, "never"] */

foo |= bar;

// gets fixed to:

foo = foo | bar;

Caveats:

  • The following cases can't be fixed:
    /* eslint operator-assignment: error */
    
    // fixing this would change the execution order of bar.valueOf() and foo.valueOf(),
    // if the function is defined for both of them
    foo = bar * foo;
    
    // fixing this would cause a `foo.bar` getter to activate only once, instead of twice.
    foo.bar.baz = foo.bar.baz + 5;
    
    // fixing this would cause bar.toString() to activate only once, instead of twice.
    // (if `bar` is a literal, this restriction is ignored)
    foo[bar] = foo[bar] + 5;

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

Nothing in particular.

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 2, 2016
@not-an-aardvark not-an-aardvark self-assigned this Nov 2, 2016
@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @btmills, @vitorbal and @scriptdaemon to be potential reviewers.

@eslintbot
Copy link

LGTM

@ilyavolodin
Copy link
Member

ilyavolodin commented Nov 11, 2016

I'm slightly concerned about enforcing += style vs. =+. While in the case of getters/setters this is more correct behavior, in simple cases, that might not be a visual style that the user wants (in simple cases, there is no functional difference between x += y and x =+ y). Since we don't have a rule that would fix the output into user defined style, I'm not sure we should attempt those fixes. I'm open to be convinced otherwise though.

@not-an-aardvark
Copy link
Member Author

I'm not sure I understand; x =+ y is doing something completely different from x += y. x =+ y sets x equal to (+y). It wouldn't make sense to do a fix to x =+ y in this case.

@ilyavolodin
Copy link
Member

Sorry, I guess I was talking more about the case of x = x + 1. Will this autofix try to change it to x += 1?

@not-an-aardvark
Copy link
Member Author

Yes, it will (assuming the user is using the "always" option).

@ilyavolodin
Copy link
Member

Actually, nevermind. I was thinking about C# for some reason:-)

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 24, 2016
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM

@nzakas nzakas merged commit 7185567 into master Nov 25, 2016
@not-an-aardvark not-an-aardvark deleted the operator-assignment-fixer branch November 25, 2016 18:22
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants