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

eol-last and no-trailing-spaces --fix interfere with each other #7866

Closed
feross opened this issue Jan 5, 2017 · 9 comments
Closed

eol-last and no-trailing-spaces --fix interfere with each other #7866

feross opened this issue Jan 5, 2017 · 9 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint rule Relates to ESLint's core rules

Comments

@feross
Copy link
Contributor

feross commented Jan 5, 2017

Tell us about your environment

  • ESLint Version: 3.12.2
  • Node Version: 7.3.0
  • npm Version: 3.10.10

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

Please show your full configuration:

{
    "eol-last": 2,
    "no-trailing-spaces": 2
}

What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
What actually happened? Please include the actual, raw output from ESLint.

If there are spaces on the last line, --fix will remove the spaces, but still add a newline.

In the following example I added characters to visualize newlines and spaces. An empty line is marked with a _ (underscore) and a space is marked with a . (dot).

Correct:

console.log('test')

becomes

console.log('test')
_

Wrong:

console.log('test')\n
..

becomes

console.log('test')
_
_

(Originally reported here: standard/standard#733)

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jan 5, 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 Jan 5, 2017
@platinumazure
Copy link
Member

What do you get for this case?

console.log('test')..\n

@johannes-z
Copy link

console.log('test')..\n

becomes

console.log('test') // all whitespaces were removed.

@feross
Copy link
Contributor Author

feross commented Jan 7, 2017

Yes, all whitespaces are removed, and the \n remains. So it becomes:

console.log('test')\n

@alberto
Copy link
Member

alberto commented Jan 7, 2017

If you don't want multiple empty lines at the end of file, you should use no-multiple-empty-lines with {maxEOF: 1}

@alberto alberto added question This issue asks a question about ESLint and removed accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly labels Jan 7, 2017
@feross
Copy link
Contributor Author

feross commented Jan 11, 2017

@alberto We're already doing "no-multiple-empty-lines": [2, { "max": 1 }] which also sets the maxEOF and maxBOF options to 1.

This appears to be a bug in the auto-fixing code.

@feross
Copy link
Contributor Author

feross commented Jan 11, 2017

Indeed, changing the setting to:

"no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 1, "maxBOF": 1 }]

does not solve the problem. The fixer still adds an extra newline at the end.

@not-an-aardvark
Copy link
Member

Correction: no-multiple-empty-lines does not count the trailing line ending in a file as a new line, so the correct config is maxEOF: 0.

@feross
Copy link
Contributor Author

feross commented Jan 11, 2017

@not-an-aardvark Ah, I think you're right.

@feross
Copy link
Contributor Author

feross commented Jan 11, 2017

Closing, as I don't think there's an ESLint bug here anymore.

Cheers, @not-an-aardvark!

@feross feross closed this as completed Jan 11, 2017
@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
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

6 participants