sveltejs / eslint-config

An ESLint config for Svelte
14 stars 11 forks source link

add rule eol-last: require newline at the end of files #6

Closed milahu closed 3 years ago

milahu commented 3 years ago

Reason for the rule mostly to make git happy

git diff shows warnings on missing newlines at end-of-file in terms of function, this will (probably) have zero effect

Examples with rule eol-last

so much trouble for just one character ------------^

Poll

Background background is compatibility with POSIX tools for example the 'word counter' wc --lines input.js prints the number of newline characters since 'one line' in POSIX is defined as 'string + newline character' and if the last line is not terminated with a \n then wc -l prints one line less (and the world ends)

Exceptions one special case is: source code for svelte code examples for aesthetic reasons, the code can be trim()med to remove whitespace at end-of-file (as it is done now) but there is no need to do this trimming in the file system so the eslint-rule can apply to these files too

original post .. to make `git diff` happy .. for compatibility with POSIX tools .. to reduce diff noise when appending to files https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline
Conduitry commented 3 years ago

I'd be in favor of this, but on the Svelte site I think we should then strip trailing whitespace when building REPL examples, so that they don't have the extra newline at the end.

milahu commented 3 years ago

what about, we hack the code editor to hide the last line number? so it shows the correct line count, as defined by posix (one line = string + newline)

or is it the one line of vertical space you want to avoid?

antony commented 3 years ago

Hi @milahu - please could you raise this according to the process here - https://github.com/sveltejs/eslint-config/issues/new/choose

Conduitry commented 3 years ago

I'd much rather try hacking the data being sent to Code Mirror than to try hacking Code Mirror.

milahu commented 3 years ago

@antony done