How to make SonarQube accept tabs instead of spaces for indentation
I’m developing a Java application as a university assignment and I’m using SonarQube for automatic code quality assessment.
Sonar is quite rigorous in spotting errors in code, and this is often useful. But it becomes annoying when Sonar floods the list of problems with multiple messages about the use of tabs instead of spaces for code indentation. Eclipse by default indents code with tabs: I think that this is the right decision and I don’t want to change that setting, even if SonarQube doesn’t like it.
So, how to configure SonarQube to accept spaces?
- Start Sonar and go to http://localhost:9000. This is the main dashboard of SonarQube.
- Log in using the link in the upper right corner of the screen. Username and password are both “admin” by default.
- Click on “Quality profiles” in the upper toolbar. You should see only one profile, called “Sonar way”.
- Use the “Copy” link to make a duplicate of this profile. Name the new profile as you want, e.g. “Sonar way (tabs)”.
- When it’s done, click on the number relative to the new profile in the “Rules” column. Sonar should come up with a list of active rules.
- Use your browser search feature to find the rule named “Tabulation characters should not be used”. Deactivate it using the button on the right.
- Using the upper toolbar, go to Dashboards -> Home, then click on your project. You should now be in the dashboard of your project.
- Choose Settings -> Quality Profiles.
- Select the new quality profile and click “Update”.
- Now, in Eclipse, you should force a full analysis of your project. To do this, run the project as “sonar:sonar” profile using Maven.You can also type mvn sonar:sonar in a terminal window in the folder that contains your pom.xml file.
- Go again in the SonarQube dashboard. Now you should no longer see the warnings about spaces.