Pylint and QualityProfile

I have configured my sonar-project.properties with following Pylint properties
sonar.python.pylint=C:\Program Files\Python36\Scripts\pylint.exe
sonar.python.pylint_config=My.pylintrc
sonar.python.pylint.reportPath=pylint-report.txt

I have got my own pylintrc configuration and I am using the standard quality profile.
I generated pylint errors in the pylint-report.txt file,

Still the sonarqube analysis is not showing the pylint errors from the report.

Could you please let me know how to show the pylint errors from the report in the sonarqube.

Thanks in advance
Mathew George

Hi,

What, if anything, does your analysis log say about this? Also, what’s your version of SonarPython?

 
Thx,
Ann

Thanks for the reply. My SonarQube version is 7.4. Where can I find the analysis log?

Hi,

Your analysis log will have been printed to the console after you typed the analysis command.

 
Ann

Please find the
sonar-project.properties
sonar.projectKey=ScbTCommon
sonar.projectName=ScbTCommon
sonar.projectVersion=1.0
sonar.sources=Sources/Framework/scbt/common
sonar.tests=Tests/Framework/scbt/common
sonar.language=py
sonar.sourceEncoding=UTF-8
sonar.python.pylint=C:\Program Files\Python36\Scripts\pylint.exe
sonar.python.pylint_config=xxxx.pylintrc
sonar.python.pylint.reportPath=pylint-report.txt
sonar.python.xunit.reportPath=nosetests.xml
sonar.python.coverage.reportPath=coverage.xml
sonar.python.coveragePlugin=cobertura

pylint-report.txt
************* Module scbt.common.generalhelper
Sources\Framework\scbt\common\generalhelper.py(36): [C0103(invalid-name)FileHelper.ReadLinesToList] Variable name “f” doesn’t conform to ‘(([a-z][A-Za-z0-9_]{2,30})|([A-Za-z0-9]*))' pattern ('(([a-z][A-Za-z0-9_]{2,30})|(_[A-Za-z0-9_]*))’ pattern)
Sources\Framework\scbt\common\generalhelper.py(13): [R0903(too-few-public-methods)FileHelper] Too few public methods (1/2)
************* Module scbt.common.logger.stdoutloghandler
Sources\Framework\scbt\common\logger\stdoutloghandler.py(88): [W0702(bare-except)StdOutLogHandler.emit] No exception type(s) specified


Your code has been rated at 9.87/10 (previous run: 9.87/10, +0.00)

Log file:
INFO: Scanner configuration file: D:\Tools\sonar-scanner\bin…\conf\sonar-scanner.properties
INFO: Project root configuration file: D:\GIT\ScbT\sonar-project.properties
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Windows 7 6.1 amd64
INFO: User cache: C:\Users\GeorgeM.sonar\cache
INFO: SonarQube server 7.4.0
INFO: Default locale: “en_US”, source code encoding: “UTF-8”
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=78ms
INFO: Server id: BF41A1F2-AWesxHfAy-I7TR7mUicM
INFO: User cache: C:\Users\GeorgeM.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=78ms
INFO: Load/download plugins (done) | time=109ms
INFO: Loaded core extensions:
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=63ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=46ms
INFO: Load active rules
INFO: Load active rules (done) | time=983ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=15ms
INFO: Project key: ScbTCommon
INFO: Project base dir: D:\GIT\ScbT
INFO: ------------- Scan ScbTCommon
INFO: Base dir: D:\GIT\ScbT
INFO: Working dir: D:\GIT\ScbT.scannerwork
INFO: Source paths: Sources/Framework/scbt/common
INFO: Test paths: Tests/Framework/scbt/common
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Load server rules
INFO: Load server rules (done) | time=343ms
INFO: Language is forced to py
INFO: Index files
INFO: 27 files indexed
INFO: Quality profile for py: Sonar way
INFO: Sensor Python Squid Sensor [python]
INFO: Sensor Python Squid Sensor [python] (done) | time=670ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Processing report ‘D:\GIT\ScbT\nosetests.xml’
INFO: Sensor PythonXUnitSensor [python] (done) | time=141ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=15ms
INFO: SCM provider for this project is: git
INFO: 5 files to be analyzed
INFO: 0/5 files analyzed
INFO: 9 files had no CPD blocks
INFO: Calculating CPD for 13 files
INFO: CPD calculation finished
INFO: Analysis report generated in 171ms, dir size=137 KB
INFO: Analysis reports compressed in 109ms, zip size=62 KB
INFO: Analysis report uploaded in 94ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=ScbTCommon
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AWhxBg7uI2WwjFus1RkE
INFO: Task total time: 5.304 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 6.864s
INFO: Final Memory: 18M/342M
INFO: ------------------------------------------------------------------------

Hi @Mathew

You should create your own profile for Python language (or use existing one if you did it already), you can inherit it from “Sonar Way”. Then activate in it rules from Pylint rules repository. As now none of the Pylint rules are in your profile, entire import of Pylint report is skipped.

P.S. You don’t need sonar.python.pylint=C:\Program Files\Python36\Scripts\pylint.exe and sonar.python.pylint_config=xxxx.pylintrc as soon as you have sonar.python.pylint.reportPath=pylint-report.txt

Docs about Pylint https://docs.sonarqube.org/x/EgU4

Hi Elena,
Thanks for reply. Could you please let me know, how to import/configure/activate pylint rules from my pylintrc?

Mathew

SonarQube doesn’t care about pylintrc if you provide report (with sonar.python.pylint.reportPath). You should activate Pylint rules through SonarQube UI. For that

  • create new profile (as you can’t edit built-in profiles, see here), set “Sonar Way” as its parent
  • open this profile, press “Activate more”, you will see list of inactive rules
  • on the facet on the left pick ‘Repository’ -> ‘Pylint’
  • you will see all available Pylint rules, press ‘bulk change’ to activate all of them

Thanks for the reply. But my situation is to configure the pylint settings similar to my pylintrc. So I would like a way to import it ? Or should I have to make it manual.

I suggest you to activate ALL Pylint rules in SQ UI, anyway only issues coming from report (thus from your pylintrc) will be reported in SQ. That’s because SQ can not report an issue for a not activated rule.
May be that’s not a perfect solution, but we don’t any automated import of pylint configuration into SQ.

Hope that helps