Sonar python rule writing

sonarqube

(Rohan Kumar) #1

Hi Team,

I am trying to modify Sonar python plugin. I added my new file with unit test and i10n files.For the first rule everything was working fine but when i added new file with unit test and i10n files, unit test of rules are ok but getting error while building the entire plugin. Please find the below error which is being caused because of rule key which is uniquely given(1st rule-s5001,2nd rule-s5002) for both the rules but it is trying to overwrite the key of first rule and displaying this is being used at multiple places:


(Alban Auzeill) #2

Hi Rohan, SonarPython does not have any rule key equals to S5001. My assumption is that you added two rules with the same key equals to S5001. Is it the case? Otherwise, could you provide more details about how you register your rules in the “python” repository.


(Rohan Kumar) #3

@alban.auzeill
I have added two new rules with different key (first rule with key S5001 and second rule with key S5002). After adding my first rule and buiulding the Sonar Python plugin code,
it worked fine(no issue untill here) but after adding scond rule with different key (S5002) it’s giving issue while building the Sonar pyhon plugin .
I have added one html and one json file at python-checks/src/main/resources/org/sonar/I10n/py/rules/python for each rule which i have added .
For rule with key S5001 i have added S5001.html and S5001.json
For rule with key S5002 i have added S5002.html and S5002.json


(Alban Auzeill) #4

Rohan, when I’m saying that “you added two rules with the same key” I mean two classes annotated with: @Rule(key = "S5001")
I can reproduce your stack trace by doing this and I get: IllegalArgumentException: The rule 'S5001' of repository 'python' is declared several times


(Rohan Kumar) #5

@alban.auzeill , Thank you

I was doing the mistake pointed out by you. Now i have changed the @Rule annotation values with correct key. It’s working fine.