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

computed-property-spacing errors with parens #12198

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

Comments

@mdjermanovic
Copy link
Member

Tell us about your environment

  • ESLint Version: 6.3.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, as well as the command that you used to run ESLint.

Demo link

/*eslint computed-property-spacing: ["error", "always"]*/

const foo = {
  [ (a) ]: 1
}
eslint index.js --fix

What did you expect to happen?

No errors.

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

4:5  error  A space is required after '('   computed-property-spacing
4:7  error  A space is required before ')'  computed-property-spacing

Fixed to:

/*eslint computed-property-spacing: ["error", "always"]*/

const foo = {
  [ ( a ) ]: 1
}

Are you willing to submit a pull request to fix this bug?

Yes.

It would be also good to clarify how should the rule handle comments.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon rule Relates to ESLint's core rules labels Sep 1, 2019
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Sep 1, 2019
@mysticatea
Copy link
Member

Thank you for your report.

It would be also good to clarify how should the rule handle comments.

We have a utility function to check spaces: sourceCode.isSpaceBetweenTokens(). It intends to ignore comments on between the tokens.

@mdjermanovic
Copy link
Member Author

Meant to ask, should this rule see comments as equal with other tokens regarding the spacing logic.

For example, should this be valid:

/*eslint computed-property-spacing: ["error", "never"]*/

foo = {
  [/**/ a /**/]: 1
}

It's currently an error, because there are spaces between the brackets and the key node (a). But, there are no spaces between the brackets and the comments and I think this should be no error.

Some other spacing rules see comments as equal:

/*eslint space-in-parens: ["error", "never"]*/

foo = (/**/ a /**/) // no error
/*eslint object-curly-spacing: ["error", "never"]*/

foo = {/**/ a /**/} // no error

While some don't:

/*eslint array-bracket-spacing: ["error", "never"]*/

foo = [/**/ a /**/] // error, autofix will delete comments

@mysticatea
Copy link
Member

It's currently an error, because there are spaces between the brackets and the key node (a). But, there are no spaces between the brackets and the comments and I think this should be no error.

Sounds good to me.

So maybe the sourceCode.isSpaceBetweenTokens() function is not useful because it cannot distinguish the space was placed on which side of the comment :)

@mdjermanovic
Copy link
Member Author

So maybe the sourceCode.isSpaceBetweenTokens() function is not useful because it cannot distinguish the space was placed on which side of the comment :)

It could be useful, the logic can be modified to pick the first token (including comments) after [ and first before ], then use sourceCode.isSpaceBetweenTokens() on those tokens and brackets.

Though, it would be good to see what should be done with #11902 first.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 22, 2020
@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 May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.