Remove trailing spaces in ecilpse

P

pd

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.
 
L

Lew

pd said:
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.
 
L

Lew

Sorry, that's five questions, of which the sixth was a rephrase. I'll learn
my numbers someday.
 
J

Jeff Higgins

pd said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top