I noticed an odd behavior of the Eclipse formatter (Strg+Alt+F) when running it on a piece of code like this:
/**
* bar
*
* @return nothing
*/
Object foo() {
return null;
}
It will add a trailing space character here:
/**
* bar
* <--- this line has a trailing space now!
* @return nothing
*/
Object foo() {
return null;
}
I know how to configure Eclipse to remove trailing whitespace, but it there a way to stop the formatter from adding it in the first place?
Click Configure. In the Code Organizing tab., enable Remove trailing whitespace for All lines. Review all the other options there, since it will all happen automatically whenever you save -- make sure there isn't anything there you don't want. Dismiss the Configure window.
Trailing whitespace is any spaces or tabs after the last non-whitespace character on the line until the newline.
You can just go to Preferences -> Java -> Editor -> Save Actions and configure it to remove trailing whitespace.
In order to do that right-click on your project and go to Properties -> Java Editor -> Save Actions. From there you can enable project specific settings and configure it to remove trailing whitespace (among other useful things).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With