Emacs can be configured to add a trailing newline by updating ~/.emacs as follows:
(setq require-final-newline t)