Why does Ruby on Rails generate add a blank line to the end of a file? -


running rails generate controller foo home results in:

class foocontroller < application controller   def home   end end (there's nothing on line in actual file, blank line) 

is there purpose blank line?

it's common use newline indicate end of line, last line. many editors (like vi, use) add in newline silently. consensus text files (especially in unix world) should end in newline, , there have been problems historically if wasn't present. why should text files end newline?

the tool used count lines in file "wc" counts newlines in file, without trailing newline show 3 instead of 4.

it improves readability of templates used in generator. consider: https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/controller/templates/controller.rb

to remove trailing newline, template have last line of:

end<% end -%> 

instead of:

end <% end -%> 

that seems less readable me.


the discussion below refers blank line earlier in file, instead of trailing newline character.

it oversight , fixed in later version of rails.

you can see in commit history here blank lines removed:

https://github.com/rails/rails/commits/master/railties/lib/rails/generators/rails/controller/templates/controller.rb

this commit removed:
remove redundant blank line @ bottom

it shows why there, adding blank line after each action.


Comments

Popular posts from this blog

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -