Remove trailing spaces in ecilpse

Discussion in 'Java' started by pd, Dec 7, 2007.

  1. pd

    pd Guest

    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.
    pd, Dec 7, 2007
    #1
    1. Advertising

  2. pd

    Lew Guest

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

    --
    Lew
    This post contains four requests for information. One of the five questions
    is a rephrasing of the preceding one.
    Lew, Dec 7, 2007
    #2
    1. Advertising

  3. pd

    Lew Guest

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

    --
    Lew
    Lew, Dec 7, 2007
    #3
  4. pd

    Jeff Higgins Guest

    pd wrote:
    > 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.
    Jeff Higgins, Dec 7, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Les Caudle
    Replies:
    0
    Views:
    599
    Les Caudle
    Mar 7, 2004
  2. John B. Matthews
    Replies:
    4
    Views:
    651
    John B. Matthews
    Sep 12, 2008
  3. Roedy Green
    Replies:
    3
    Views:
    609
  4. johkar
    Replies:
    2
    Views:
    2,841
    Mayeul
    Dec 10, 2009
  5. Dan van Ginhoven

    remove CR + trailing spaces

    Dan van Ginhoven, Dec 19, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    106
    Dr.Ruud
    Dec 19, 2007
Loading...

Share This Page