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
RefactoringImpl
interface. TheperformRefactoring
-method will contain all the logic of the refactoring. I recommend to write a simple unit test first (see step 5). - Open
RefactoringOperations.java
and 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.java
and translate the rule to your recently added refactoring operation (check out theswitch (issue.getRule())
and extend this part). - Under
src/test/java
add a resources class (= example of a class containing the code smell), usually starting withTestDataClass...
. 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.