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

object-curly-spacing with line comment #11902

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

@alfredking1988
Copy link

Tell us about your environment

  • ESLint Version: 6.0.1
  • Node Version: 10.16.0
  • npm Version: 6.8.0

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:

Configuration
{
  root: true,
  rules: {
    'object-curly-spacing': 'error',
  },
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

var o = { // hello, this is the line comment, which should be ok
  n: 42,
};
eslint test.js

What did you expect to happen?
ESLint should pass without error

What actually happened? Please include the actual, raw output from ESLint.
ESLint output error:
1:9 error There should be no space after '{' object-curly-spacing

Note
Maybe there should an option for this rule, to allow space after the { if trailing comment exists?

@alfredking1988 alfredking1988 added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jun 25, 2019
@aladdin-add aladdin-add added 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 Jun 25, 2019
@g-plane
Copy link
Member

g-plane commented Jun 25, 2019

I can reproduce this bug: Reproduction Link.

@g-plane g-plane 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 Jun 25, 2019
@kaicataldo
Copy link
Member

It does seem to me like the rule should ignore white space around comments after the opening brace and before the closing brace when there are line breaks.

@mdjermanovic
Copy link
Member

It does seem to me like the rule should ignore white space around comments after the opening brace and before the closing brace when there are line breaks.

Ignore the brace regardless of the options if the first non-comment token is on another line?

@silverwind
Copy link
Contributor

silverwind commented Aug 12, 2019

This is a regression in 6.x, it did pass in 5.x. I suspect 67c08b6 introducted the regression.

@mdjermanovic
Copy link
Member

I don't think this is a bug, the rule now works with comments same as with all other tokens.

Nevertheless, there is already a precedent for this particular exception, e.g. space-in-parens allows this:

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

var foo = ( // No errors. The option is 'never', but spaces between '(' and '//' are allowed
  bar
);

The above is the only exception, the following are still errors:

/*eslint space-in-parens: ["error", "always"]*/
var foo = (//
  bar
);

/*eslint space-in-parens: ["error", "always"]*/
var foo = (/**/ 
  bar
);

/*eslint space-in-parens: ["error", "always"]*/
var foo = (
  bar
/**/);

/*eslint space-in-parens: ["error", "never"]*/
var foo = ( /**/
  bar
);

/*eslint space-in-parens: ["error", "never"]*/
var foo = ( 
  bar
/**/ );

I think it's okay to allow only this particular exception (never + line comment) in object-curly-spacing as a small change in the default behavior.

@mdjermanovic
Copy link
Member

block-spacing and comma-spacing also have exception for line comments.

I'm working on this.

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