Standard: Enforce only 1 newline at end of file (currently 1-2 are allowed)

Created on 5 Jan 2017  路  3Comments  路  Source: standard/standard

If there are spaces on the last line, standard --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')
_
_
bug

Most helpful comment

This will be part of standard v9. There were 12 repos that failed, but this is trivial to fix, is also automatically fixable with --fix, and was an enforced rule in the past (this was a regression).

All 3 comments

This looks like an ESLint bug, so I opened an issue there: https://github.com/eslint/eslint/issues/7866

Turns out the way ESLint counts lines at the end of the file is a bit wonky. They don't count the last \n, so we actually need to set maxEOF: 0 on the no-multiple-empty-lines rule:

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

That fixes this issue, and also another issue with standard right now, which is that we allow either 1 or 2 newlines at the end of a file. 馃憤

This will be part of standard v9. There were 12 repos that failed, but this is trivial to fix, is also automatically fixable with --fix, and was an enforced rule in the past (this was a regression).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

feross picture feross  路  3Comments

hzhu picture hzhu  路  3Comments

christianalfoni picture christianalfoni  路  3Comments

jcalfee picture jcalfee  路  3Comments

jescalan picture jescalan  路  3Comments