3

JSHint complains when, at the end of the file, there is no line feed. Here is an example:

Missing line feed at file end at app/services/cache.js :
    14 |
    15 |  });
    16 |})();
-------------^

What's the purpose of having this line feed? What difference would it make?

Badacadabra
  • 8,043
  • 7
  • 28
  • 49
runtimeZero
  • 26,466
  • 27
  • 73
  • 126
  • 4
    it's mostly a convention, and it has advantages when you work on a command line. If you do `cat cache.js`, for example, it's nice if the newline is there. Otherwise, your command prompt would look like this: `})();james@localhost$` – amenthes Aug 03 '15 at 11:33
  • 1
    You can read more about it here: http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline – Przemysław Jan Wróbel Aug 03 '15 at 11:35

1 Answers1

1

If you're using the .js file directly in HTML or NodeJS and you edit it entirely using IDE's like WebStorm or Sublime, etc., then there is no real advantage.

If later in your build and deployment you are using something like Gulp to concatenate multiple .js files like cache.js and edit.js together into one master.js, then the last line of cache.js is going to be in the same line as the first line of edit.js.

That is if cache.js, as you wrote, has no line feed and ends with the following

  });
})();

and say you had another file edit.js that you concatenate into one master.js using a tool like Gulp and edit.js starts with the following

/* a really krufty set of code for editing barrels of kittens */
$().read(function() {
    // ... da code be here ...

then your final master.js will have a line like this

})();/* a really krufty set of code for editing barrels of kittens */

Is there anything wrong with that? No, not really. Might make it harder to debug or read later depending on the lines in question.

And, as amenthes has commented, command line tools like cat and wc -l aren't going to give expected results.

And, as Przemysław Jan Wróbel led me to see, there is a fantastic answer here https://stackoverflow.com/a/25322168/266531

Community
  • 1
  • 1
Kirby
  • 15,127
  • 10
  • 89
  • 104