There are multiple gedit plugins that allow you to do this when saving the file. This plugin allows you to do this when explicitly asked to, and if something is selected, it acts on selected lines only.
Press Ctrl + Shift + R to strip trailing whitespace from all lines in the document (or in the selection if anything selected).
By whitespace I currently mean tabs and spaces only.
- Make sure your gedit version is up to date.
- Copy project folder to
~/.local/share/gedit/plugins
- Enable this plugin.