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

no-extra-bind fix could be unsafe #10846

Closed
helixbass opened this issue Sep 9, 2018 · 2 comments

Comments

@helixbass
Copy link
Contributor

commented Sep 9, 2018

Tell us about your environment
Came across this while testing no-extra-bind for Coffeescript custom parser

  • ESLint Version:
    5.5.0
  • Node Version:
    8.11.4
  • npm Version:
    6.2.0

What parser (default, Babel-ESLint, etc.) are you using?
Coffeescript custom parser (but the issue is the same with standard parser)

Please show your full configuration:
The relevant configuration is no-extra-bind: error with fixing enabled

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

I noticed that no-extra-bind when fixing blindly removes the .bind(...) without inspecting the argument to .bind(). This seems like it could change meaning if the argument is not side-effect-free

For example:

function () {}.bind(a())

or:

function () {}.bind(b++)

What did you expect to happen?
It should presumably still report the unnecessary .bind() but not fix if it's unsafe to remove the .bind(...)

What actually happened? Please include the actual, raw output from ESLint.
The fix removed the .bind(...)

I could take a crack at fixing this but it'd be helpful to know if there are already established patterns for checking if a node is "side-effect-free"?

@eslint eslint bot added the triage label Sep 9, 2018

@not-an-aardvark not-an-aardvark added bug rule accepted and removed triage labels Sep 9, 2018

@not-an-aardvark

This comment has been minimized.

Copy link
Member

commented Sep 9, 2018

Thanks for the report, I can reproduce this issue.

I could take a crack at fixing this but it'd be helpful to know if there are already established patterns for checking if a node is "side-effect-free"?

Not that I know of. I think the list of "side-effect-free" nodes is fairly small -- it seems like it would typically just contain identifiers, literals, and function expressions. (There are some other cases where things could be guaranteed to be side-effect-free, such as empty objects or class expressions without any computed method names, but it doesn't seem necessary to cover every case since this just affects whether an autofix is attempted.)

@platinumazure

This comment has been minimized.

Copy link
Member

commented Oct 4, 2018

Working on this.

platinumazure added a commit that referenced this issue Oct 5, 2018

@eslint eslint bot locked and limited conversation to collaborators Apr 11, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.