The `stripspace.el' Emacs package offers `stripspace-local-mode', which ensures that trailing whitespace is removed before saving a buffer.