Tab and white spaces in Eclipse

Published by Tobias Hofmann on

1 min read

When you decide to analyze your source code with a quality tool like SonarQube, sooner or later you will get messages about trailing white spaces or to replace tab with white spaces. The severity is minor and if you now use tab or white space for indentation has no effect whatsoever on my final code. At the end I run grunt and uglify over the code and unnecessary spaces are eliminated. But you may get into other problems with space / tab:

  • Git code review
  • Changes between operating systems (Linux, Windows)
  • Unreadable code when opened in Wordpad / Notepad / vim
  • Tab is normally 4 white spaces, but when defined differently on a computer, code gets really unreadable
  • Angry developers in endless flame wars

Now, what do to when SonarQube is showing minor problems caused by tabs?

This is caused that by default Eclipse is using tabs to indent code. You cannot change the default profile, but you can define your own. To do so, follow these steps:

  1. Create a new profile

    Windows -> Preferences

    Click on New…

    Inform a nice profile name.

  2. Alter indentation

    Change the tab and white space setting.

    Change tab policy to spaces only

To apply the new profile to an already edited file, you can open the file and re-format it (CTRL+SHIT+F). Running a new SonarQube analysis eliminates the white space errors:

Let the world know

Tobias Hofmann

Doing stuff with SAP since 1998. Open, web, UX, cloud. I am not a Basis guy, but very knowledgeable about Basis stuff, as it's the foundation of everything I do (DevOps). Performance is king, and unit tests is something I actually do. Developing HTML5 apps when HTML5 wasn't around. HCP/SCP user since 2012, NetWeaver since 2002, ABAP since 1998.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.