GitHub - SonarSource/sonar-python: 🐍 SonarQube Python plugin (original) (raw)

Python analyzer for SonarQube, SonarCloud, and SonarLint

Sonar's Clean Code solutions help developers deliver high-quality, efficient code standards that benefit the entire team or organization.

Building the project

Fast/minimal build

Prerequisites:

The easiest way to build the Project is by running:

mvn clean install -DskipTypeshed -P-private

It builds only Java Maven modules, runs tests, and installs jar locally. The Python interpreter is not required in that case.

Full build

Prerequisites:

cd python-frontend/typeshed_serializer/resources/python-type-stubs
git sparse-checkout set stubs/sklearn 
git checkout

All the above should be available in PATH.

To execute the full build just run:

mvn clean install -P-private

The full build executes Typeshed serializer script. It generates protobuf messages for Typeshed symbols (for standard Python API) and our customs symbols (for Python libraries, e.g. AWS CDK). This helps with type inference and providing better rules.

How to contribute

Configuration

First, please configure your IDE:https://github.com/SonarSource/sonar-developer-toolset.

Rule annotation

Each new implemented rule should have @Rule(key = "S0000") annotation on the class level. The number of the rule can be found here: https://sonarsource.github.io/rspec/#/rspec/?lang=python. The key is usually automatically generated by a rspec repository GitHub action and needs to be unique in the whole project.

Expectations:

Before push

Please check if all files have a license header. If not, the mvn install will fail with the Some files do not have the expected license header message. To fix that please execute: mvn license:format.

License

Copyright 2011-2024 SonarSource.

SonarQube analyzers released after November 29, 2024, including patch fixes for prior versions, are published under the Sonar Source-Available License Version 1 (SSALv1).

See individual files for details that specify the license applicable to each file. Files subject to the SSALv1 will be noted in their headers.