guys,
i am using eclipse 3.2.2. in my preferences i have set spaces for the
tab key. now when i run checkstyle on my code, it says that the lines
contain trailing spaces. can somebody tell me how i can fix this.
i have already set the setting to spaces, so what else can i change
now. thanks.
Lew - 07 Dec 2007 05:36 GMT
> i [sic] am using eclipse 3.2.2. in my preferences i [sic] have set spaces for the
> tab key. now when i [sic] run checkstyle on my code, it says that the lines
> contain trailing spaces. can somebody tell me how i [sic] can fix this.
Is "checkstyle" part of Eclipse?
> i [sic] have already set the setting to spaces, so what else can i [sic] change
> now. [sic] thanks.
Have you examined the lines that have trailing spaces?
When did the IDE add the spaces? What did you do, e.g., reformat the source,
hit newline, to which the IDE reacted by adding spaces at the end of the
line(s)?
Did it add them to all lines or just certain ones? If the latter, which ones?
Sometimes IDEs will indent an empty line and it will be nothing but spaces.
public void trailingSpaces()
{
int foo;
String s =
"The above line has two spaces, therefore it has trailing spaces.";
}
I haven't seen them add spaces at the end of non-empty lines, though.
I use a regex search-and-replace for " +$" => "". (Find "space-plus-dollar";
replace with empty string.) It'll take care of trailing spaces whether or not
the line has other stuff on it.

Signature
Lew
This post contains four requests for information. One of the five questions
is a rephrasing of the preceding one.
Lew - 07 Dec 2007 05:45 GMT
Sorry, that's five questions, of which the sixth was a rephrase. I'll learn
my numbers someday.

Signature
Lew
Jeff Higgins - 07 Dec 2007 12:32 GMT
> guys,
>
[quoted text clipped - 4 lines]
> i have already set the setting to spaces, so what else can i change
> now. thanks.
This applies to Eclipse 3.3.0
I don't know if it applies to 3.2.2.
Go to Preferences, Java, Code Style, Clean Up.
Select Edit..., Select Code Organizing.
Check Remove trailing whitespace.
Select All lines, or Ignore empty lines.
Save your new profile.
You can run Clean Up from the Source menu.
*There is a way to run Clean Up when saving files,
but I cannot find it at this moment.
Note that this will apply ALL clean up rules.
You can also bind the Remove Trailing Whitespace
command to a key if you like.
Go to Preferences, General, Keys.
Check Include unbound commands.
Scroll to the Remove Trailing Whitespace command.
Select a key binding.
*I'm sure you can add this command to a menu item
if you wish, but I don't know how off the top of my head.