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-newline --fix erroneously removes comment #8484

Closed
freshp86 opened this issue Apr 19, 2017 · 3 comments
Closed

object-curly-newline --fix erroneously removes comment #8484

freshp86 opened this issue Apr 19, 2017 · 3 comments
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

@freshp86
Copy link

freshp86 commented Apr 19, 2017

ESLint Version: v3.19.0
Node Version: v7.9.0

module.exports = {
  'env': {
    'browser': true,
    'es6': true
  },
  'extends': 'eslint:recommended',
  'rules': {
    'object-curly-newline': ['error', {multiline: true}],
    'no-unused-vars': 'off',
  }

Before

var a = {
  // Nothing here yet, but comment should not be removed.
};

After invoking ESLint with the --fix flag the file is modified as follows

var a = {};

What did you expect to happen?
The comment should have been preserved.

What actually happened?
The comment was removed.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Apr 19, 2017
@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Apr 20, 2017
@platinumazure
Copy link
Member

Thanks for reporting this! We definitely don't want to remove comments via autofix.

@freshp86
Copy link
Author

Thanks for triaging quickly. Just adding a few more cases that exhibit the same problem

Before

let a = { 
  /* comment */ foo: 'hello'
};

let b = { 
  foo: 'hello' /* comment */
};

After --fix both comments are removed

let a = {foo: 'hello'};

let b = {foo: 'hello'};

@freshp86
Copy link
Author

freshp86 commented Apr 20, 2017

FYI, I have a condidate fix at https://github.com/freshp86/eslint/commit/496568626008a44652d5e41aebc9295d64f92f97. Tested

let a = {
  /* comment */ foo: 'hello'
};

let b = {
  foo: 'hello' /* comment */
};

let c = { /* comment */
  foo: 'hello'
};

let d = {
  /* comment */
}

and it becomes

let a = {/* comment */ foo: 'hello'};

let b = {foo: 'hello' /* comment */};

let c = { /* comment */
  foo: 'hello'
};

let d = {/*comment*/};

which seems correct. If that seems promising I can look on how to add proper tests and send a PR (have not contributed to ESLint before).

Having said that, when I use my complete config object (not posted in this bug), I end up with the comments removed again. I'll keep investigating that separately, since that seems to be caused by some other rule.

schempy added a commit to schempy/eslint that referenced this issue Jul 14, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 14, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 14, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 17, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 17, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 19, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 19, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 20, 2017
schempy added a commit to schempy/eslint that referenced this issue Jul 20, 2017
References rule object-curly-newline. Avoid fixing line breaks when the
token after opening brace is a comment or token before closing brace is
a comment.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 a pull request may close this issue.

3 participants