How to implement a refactoring to remove a code smell - Refactoring-Bot/Refactoring-Bot GitHub Wiki

This page briefly describes how to implement a new refactoring for removing a code smell found by SonarQube.

  1. Add a new class in the refactoring package, next to the other refactoring classes. Name the class so that it describes the refactoring well. Your new class must implement the RefactoringImpl interface. The performRefactoring-method will contain all the logic of the refactoring. I recommend to write a simple unit test first (see step 5).
  2. Open RefactoringOperations.java and add your refactoring to the ruleToClassMapping.
  3. Find the key of the SonarQube rule (usually in the top right corner of a rule description, e.g. squid:S1488).
  4. Open SonarQubeObjectTranslator.java and translate the rule to your recently added refactoring operation (check out the switch (issue.getRule()) and extend this part).
  5. Under src/test/java add a resources class (= example of a class containing the code smell), usually starting with TestDataClass.... Also add a test class ...Test.java and implement unit tests for your refactoring. Look at the existing tests (e.g. AddOverrideAnnotationTest) for reference. We are also always happy to help if something is unclear or help is needed.