Awesome
SonarDelphi is a modern, performant, and fully-featured community code analyzer for the Delphi language. As a plugin for the SonarQube code analysis platform, it can be easily integrated into existing workflows.
This project has three primary goals:
- Correctness: All valid Delphi code should be accepted and understood correctly.
- Utility: Analysis results should be easily understandable and immediately actionable.
- Extensibility: New rules should be trivial to add and have access to the full power of the analyzer.
This project aims to follow the conventions and best practices of SonarQube's official analyzers. It is actively maintained by a core team and is open for community contributions.
Features
With SonarDelphi, you can:
- Analyze Delphi code, identifying issues from more than 120 rules
- Create custom rules in the SonarQube UI from templates
- Import NUnit test reports (compatible with DUnitX)
- Import test coverage reports (compatible with DelphiCodeCoverage)
Semantic analysis
SonarDelphi understands what your code means, paving the way for powerful rules such as:
- Variables must be initialized before being used
- Name casing should be kept consistent
- FreeAndNil must only be passed an instance of a TObject descendant
- Constructors should not be invoked on object variables
- The Single overloads of the standard math functions should not be used
- Redundant casts should not be used
- Platform-dependent casts should not be used
- Unicode types should not be cast to ANSI types
- 'Format' calls should be supplied arguments of the correct type
- Your own custom rules to enforce a naming convention for descendants of specific types
- Your own custom rules to forbid usage of types, routines, properties, identifiers, constants, enum values, or units
Dead code analysis
Using semantic analysis, SonarDelphi can identify unused code in your project, including:
- Unused imports
- Unused types
- Unused routines
- Unused properties
- Unused fields
- Unused local variables
- Unused constants
Advanced custom rules
In addition to template rules, SonarDelphi can be extended with custom rules plugins:
- Leverage the full power of the analysis engine with the SonarDelphi rules API.
- For more details, see Writing Custom Delphi Rules.
Quickstart
-
Install the following:
- SonarQube (v9.9+)
- SonarScanner
- Delphi
-
Install the plugin:
- Download the SonarDelphi plugin from Releases.
- Install the plugin on the SonarQube server.
-
Run analysis on your Delphi project:
- Configure your Sonar project, including
sonar.delphi.installationPath
. - Execute
sonar-scanner
in your project's directory.
- Configure your Sonar project, including
-
View analysis results:
- Visit the link provided at the end of the scan to view analysis results on SonarQube.
Read the Manual
The SonarDelphi Manual provides a comprehensive guide to SonarDelphi and the Sonar ecosystem, including:
- An introduction to SonarQube
- How to configure SonarDelphi projects and scans
- How to customize analysis rules
[!TIP] It is strongly recommended that first-time SonarQube users read the "SonarQube from first principles" section of the manual.
Contributing
SonarDelphi is open for contributions, from bug reports to new features. For more details, please read the contributing guide.
Development
SonarDelphi can be built with JDK 11+ using Maven.
To build the project and run unit tests, execute the following command from the project's root directory:
mvn clean install
After building, the plugin jar can be found in sonar-delphi-plugin/target
.
History
In 2012, Sabre Airline Solutions released SonarDelphi as an open source project. Over the years, it has been forked and iterated on by various maintainers.
In 2018, it was picked up as a Monash University student project for IntegraDev. Since 2019, the project has been actively developed and extensively rewritten by IntegraDev.
License
Licensed under the GNU Lesser General Public License, Version 3.0.