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

Closed
mdjermanovic opened this issue Sep 1, 2019 · 4 comments · May be fixed by rsumner868/librealsense2.1#1, rsumner868/librealsense#4, O330oei/node#4 or O330oei/node#11

Comments

@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented Sep 1, 2019

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.

@mysticatea mysticatea added accepted and removed triage labels Sep 1, 2019
@mysticatea
Copy link
Member

@mysticatea mysticatea commented Sep 1, 2019

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

@mdjermanovic mdjermanovic commented Sep 1, 2019

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

@mysticatea mysticatea commented Sep 1, 2019

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

@mdjermanovic mdjermanovic commented Sep 1, 2019

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.

@btmills btmills closed this in 62c7038 Nov 22, 2019
@eslint eslint bot locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.