Automate fixes for issues found by Sonar

Viewed 17096

I am working on fixing issues caught by sonar on a very old Java project(8 years old approximately ). It is a huge project with a lot of faulty code that is caught by sonar. Although they are very trivial fixes but there are a number of them. Is there a way to automatically fix a series of similar issues ? Like i have around 1200 cases of "statements should be on separate lines" , to do it manually would take ages. Can i automate these fixes somehow ?

7 Answers

Currently there are no tools available for automatic fixing of sonarube bugs. There is walkmod, but it is only for trivial code-smells.

I am currently writing an automatic repair tool for sonarube bugs in java. It uses INRIA's spoon to fix the bugs. The github repo is sonarqube-repair. It has fixes for five bugs: rule numbers 1854, 1948, 2055, 2259 and 2095. I will update this answer once there is some significant progress.

Do it step by step (for Eclipse IDE):

  1. You can use Save action on your whole project: Right-click on your Java project source -> Source -> Format...
  2. Right-click on your Java project source -> Source -> Clean Up...
  3. Use the AutoRefactor plugin: Right-click on your code -> AutoRefactor -> Automatic refactoring
  4. Use WalkMod (not tested).

You could use Viofixer tool - https://www.viofixer.com/

VioFixer does automatic remediation of the issues reported by sonarqube. VioFixer help reduce the development time and secures completed applications by providing automatic vulnerability remediation options in the coding stage of software development.

Now JavaPerf Consulting launches a service offering tooled to resolve faults identified by SonarQube see more http://www.jperf.com. Soon you will have the product with a command line interface and automatic update.

Related