V1.8.0 - Trim trailing white spaces and add new line at eof

Rebased version of #1023