Most linters from different programming languages, such as RuboCop (Ruby) and JSLint (JavaScript) recommend a blank line at the end of all code files. As an example, RuboCop:
RuboCop :: Cop :: Style :: FinalNewLine
This cop reinforces the presence of a blank final line in each source file. (adapted from RubyDoc)
In addition to linters , even Git, when running git diff
, indicates when there is no blank line at the end of the code files:
No newline at end of file
To illustrate, the result is:
1 def say_hi
2 puts 'hi'
3 end
4
5 say_hi
6
Is it just a convention? Is there a difference in putting a blank line at the end of my code and not putting it?