How to create Custom rules in Sonarqube for Python Code?

Hi ,

I am trying to add a custom rule for my python code where i need to scan logging statements containing payload values in the submodules. These values are present in the submodule which in separate scm repository and it is used via .gitmodules . I am able to see the submodule in the code tab of the sonarqube project.

logging.info(payload)

I need the rule to scan above line and provide below suggestion

logging.info(json.dumps(payload))

. I tried creating by selecting rules and filtering with python profile and provided the details in the description and ran the analysis but it is not working …

I have also provided sonar.scm.exclusions.disabled=true.
Am I missing any steps here ?

I am not able to provide the complete implementation as it is confidential.

Thanks,

Hi,

Welcome to the community!

Without some idea of what you’ve tried (i.e. the code) it’s going to be difficult to give concrete help.

 
Ann

Logs -
Logs.txt (7.3 KB)

Test file -

May i know if i am missing any step here

Hi,

If you’re writing custom rules, your analysis log & issue screenshot(?) won’t help us help you. We need to see your code.

 
Ann

Hi ,

Above are the steps i tried …

  1. Created a TEST.py file with logging statement
  2. Created a rule “PI Statement” from the rule template of python language
  3. Added the rule to Quality profile
  4. Ran the analysis.

Is there any other steps i need to perform?