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: Check computed method keys in no-extra-parens #11973

Merged
merged 2 commits into from Aug 3, 2019
Merged

Update: Check computed method keys in no-extra-parens #11973

merged 2 commits into from Aug 3, 2019

Conversation

mdjermanovic
Copy link
Member

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

[X] Bug fix

Tell us about your environment

  • ESLint Version: 6.0.1
  • 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: 6,
  },
  rules: {
    "no-extra-parens": "error"
  }
};

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

class foo {
  *[(Symbol.iterator)]() {}

  get [(a)]() {}
  set [(a)](bar){}

  static [(b)](){} 
}

What did you expect to happen?

4 errors.

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

No errors.

What changes did you make? (Give an overview)

Added ClassBody() to no-extra-parens.

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

  • I guess this is a bug fix that adds more reported warnings, rather than a new behavior.
  • The same could be done with MethodDefinition(), but ClassBody() allows to easily check computed
    public instance fields and static class fields (both are babel-eslint's "ClassProperty") in the future.
    Actually, it can be easily done now (without the member.type === "MethodDefinition" condition the code would simply check anything in the class body that has computed === true ), but I'm not sure is it OK to do it at this moment.
  • class a { [b, c](){} } is indeed a syntax error without parens around the sequence expression.

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

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

Thanks for contributing, and the kindly description! :)

public instance fields and static class fields is in stage-3, it means eslint don't officially support. So I don't think we can add tests for this. But other cases LGTM!

@aladdin-add aladdin-add added 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 Jul 11, 2019
@mdjermanovic
Copy link
Member Author

I could copy output from babel-eslint and paste it somewhere in ../tests/fixtures/parsers

My comment was probably confusing. The question is - should this rule, at this moment, remove parens around computed keys of stage 3 class members, or simply ignore them? This commit ignores them (member.type === "MethodDefinition"' filter).

@platinumazure
Copy link
Member

The question is - should this rule, at this moment, remove parens around computed keys of stage 3 class members, or simply ignore them?

I think it's okay to ignore those cases for now. eslint-plugin-babel or similar plugins could extend the rule to support those stage 3 cases.

@mdjermanovic
Copy link
Member Author

The question is - should this rule, at this moment, remove parens around computed keys of stage 3 class members, or simply ignore them?

I think it's okay to ignore those cases for now. eslint-plugin-babel or similar plugins could extend the rule to support those stage 3 cases.

OK, then there is nothing to change now, the commit is in line with this.

Maybe just to add a couple of babel test cases to show that the rule does not crash on such input?

@platinumazure
Copy link
Member

Maybe just to add a couple of babel test cases to show that the rule does not crash on such input?

I don't think that's necessary at this point, but other team members might feel differently.

Copy link
Member

@aladdin-add aladdin-add 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!

lib/rules/no-extra-parens.js Outdated Show resolved Hide resolved
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 for contributing!

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly and removed 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 labels Jul 11, 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.

Would you resolve conflicts?

@mdjermanovic mdjermanovic changed the title Update: Check computed method keys in no-extra-parens WIP: Update: Check computed method keys in no-extra-parens Jul 17, 2019
@mdjermanovic
Copy link
Member Author

I''ll resolve this better when I get back from travel.

@mdjermanovic mdjermanovic changed the title WIP: Update: Check computed method keys in no-extra-parens Update: Check computed method keys in no-extra-parens Aug 2, 2019
@mdjermanovic
Copy link
Member Author

Rebased and ready for review now.

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!

@platinumazure platinumazure merged commit f5e0cc4 into eslint:master Aug 3, 2019
@platinumazure
Copy link
Member

Thanks @mdjermanovic for contributing! I appreciate your patience as we sorted this one out 😄

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 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

4 participants