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.
- 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
RefactoringImplinterface. TheperformRefactoring-method will contain all the logic of the refactoring. I recommend to write a simple unit test first (see step 5). - Open
RefactoringOperations.javaand add your refactoring to theruleToClassMapping. - Find the key of the SonarQube rule (usually in the top right corner of a rule description, e.g.
squid:S1488). - Open
SonarQubeObjectTranslator.javaand translate the rule to your recently added refactoring operation (check out theswitch (issue.getRule())and extend this part). - Under
src/test/javaadd a resources class (= example of a class containing the code smell), usually starting withTestDataClass.... Also add a test class...Test.javaand 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.