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: Fix handling of property names in no-self-assign #12105

Merged
merged 1 commit into from Sep 14, 2019
Merged

Update: Fix handling of property names in no-self-assign #12105

merged 1 commit into from Sep 14, 2019

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Aug 16, 2019

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

[X] Bug fix

This is a bug fix to remove false positives, but it's fixed in a way that can produce a few more warnings.

Please see is it ok, the details are below.

Tell us about your environment

  • ESLint Version: 6.1.0
  • Node Version: 10.16.0
  • npm Version: 6.9.0

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.

An example:

/*eslint no-self-assign: "error"*/

({ "foo": a } = { "bar": a });
({ 1: a } = { 2: a });
({ "foo": a } = { 1: a });
({ 1: a } = { "bar": a });

Demo link

What did you expect to happen?

No warnings.

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

  3:26  error  'a' is assigned to itself  no-self-assign
  4:18  error  'a' is assigned to itself  no-self-assign
  5:22  error  'a' is assigned to itself  no-self-assign
  6:22  error  'a' is assigned to itself  no-self-assign

What changes did you make? (Give an overview)

The code was assuming that all non-computed keys are identifiers and matched them by undefined === undefined.

It's fixed to compare keys by their getStaticPropertyName values.

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

These would be new warnings:

/*eslint no-self-assign: "error"*/

({ "foo": a } = { foo: a });
({ ["foo"]: a } = { foo: a });
({ ["foo"]: a } = { "foo": a });
({ ["foo"]: a } = { ["foo"]: a });
({ [1]: a } = { 1: a });

Is it okay for a semver-minor fix? I can modify the code to just remove false positives.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Aug 16, 2019
@platinumazure
Copy link
Member

Is it okay for a semver-minor fix?

I think the question is, should the rule definitely be reporting those issues (could there be a good reason we weren't reporting those cases)? If the current behavior is not according to design, then this is acceptable as a semver-minor fix.

I lean toward that interpretation, but please let me know if I missed something.

@mdjermanovic
Copy link
Member Author

I've edited the post to add ({ ["foo"]: a } = { ["foo"]: a }); to the list of new warnings.

As for ({ "foo": a } = { foo: a }); it was probably due to the missed fact that non-computed keys can be literals. I guess it could be ok to add at least these warnings, this was a bug that also produced false positives.

As for why 'simple' computed keys were not compared, the code is very explicit and it was certainly by design, probably before they were treated as statically known in other rules as well.

@mdjermanovic
Copy link
Member Author

Most of the rules use getStaticPropertyName and treat ["a"] same as "a" and a.

Was there a precedent of this particular change in a minor version?

The safest thing here would be to revert that part and ignore all computed keys, it would be similar to how no-dupe-class-members works at the moment.

On the other hand, that rule does match "a" with a, I believe that part can be seen as a bug fix for a minor version (that's basically the same bug that caused false positives).

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 24, 2019
Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic
Copy link
Member Author

Are all new warnings acceptable for semver-minor?

(I didn't change anything after the initial commit)

@platinumazure
Copy link
Member

platinumazure commented Sep 6, 2019

@mdjermanovic No, but I thought about this case and I can't see any reason why the rule would want to distinguish between property assignments vs literals as a matter of design.

In this case, I evaluated the probability that people were depending on the current, specific behavior with differences between literals and property names, and decided that the probability was very low. But again, that's just my own evaluation.

We do have precedent about adding warnings in semver-minor where the enhancement just seems natural. (E.g., a stylistic rule about var declarations could be naturally expanded to let and const declarations.)

If other team members feel differently, I certainly have no problem with adding an option.

@mdjermanovic
Copy link
Member Author

@platinumazure I agree, this is a too 'small' change in behavior to be an option.

@mysticatea mysticatea 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 Sep 12, 2019
@mysticatea
Copy link
Member

I'm fine with semver-minor (A bug fix in a rule that results in ESLint reporting more errors). If the rest of the team have no objection, I will merge this PR within the next release.

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.

LGTM, thanks!

@ilyavolodin ilyavolodin removed the bug ESLint is working incorrectly label Sep 14, 2019
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

5 participants