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

Disallow spaces inside of computed keys of class methods, getters and setters (computed-property-spacing) #1416

Closed
feross opened this issue Sep 14, 2019 · 2 comments

Comments

@feross
Copy link
Member

feross commented Sep 14, 2019

https://eslint.org/docs/rules/computed-property-spacing

Current rule:

"computed-property-spacing": ["error", "never"],

Proposed rule:

"computed-property-spacing": ["error", "never", { "enforceForClassMembers": true }],

By default, this rule does not check class declarations and class expressions,
as the default value for enforceForClassMembers is false.

When enforceForClassMembers is set to true, the rule will also disallow/enforce spaces inside of computed keys of class methods, getters and setters.

Examples of incorrect code for this rule with "never" and { "enforceForClassMembers": true }:

/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/

class Foo {
  [a ]() {}
  get [b ]() {}
  set [b ](value) {}
}

const Bar = class {
  [ a](){}
  static [ b]() {}
  static get [ c ]() {}
  static set [ c ](value) {}
}

Examples of correct code for this rule with "never" and { "enforceForClassMembers": true }:

/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/
/*eslint-env es6*/

class Foo {
  [a]() {}
  get [b]() {}
  set [b](value) {}
}

const Bar = class {
  [a](){}
  static [b]() {}
  static get [c]() {}
  static set [c](value) {}
}
@mightyiam
Copy link
Member

All in, of course. BTW, this is another example where ESLint is getting closer to the level of prettier. I know it's quite far and has a long way to go in that regard, but still... personally, for me, it's close enough. And since it keeps getting better (if the available rules are used) then I'm happy with it.

@feross feross modified the milestones: standard 15, standard 16 Oct 22, 2020
@feross
Copy link
Member Author

feross commented Oct 29, 2020

No ecosystem failures!

This will ship in standard 16.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants