Skip to content

SonarQube plugin for static code analysis of Scala projects.

License

Notifications You must be signed in to change notification settings

andreasowczarek/sonar-scala

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sonar-scala

circleci-badge coverage-badge bintray-badge bintray-stats-badge gitter-badge insightio-badge

SonarQube plugin for static code analysis of Scala projects.

Intended for SonarQube 6.7+ LTS and Scala 2.11/2.12.

This plugin is not an evolution from the legacy sonar-scala-plugin of which versions can be found laying around such as 1and1/sonar-scala. The previous plugin used the scala compiler to create its metrics which had the disadvantage of requiring a specific plugin per each major version of Scala. Instead, this plugin uses the scala-ide/scalariform library to parse the source code in a version independent way.

Supported Metrics

This plugin currently supports the following SonarQube metrics:

In addition to the above, the plugin reports the following custom metrics, which are extracted from the Scoverage report:

Quality Rules and Profiles

This plugin integrates 75 quality checks from Scalastyle. 46 of them are quality rules without parameters which work out of the box and the remaining 29 are rule templates that allow you to set up custom rules which can be configured by various parameters.

The rules in the Scalastyle quality profile, created by this plugin, are almost all deactivated. In order to use all of the rules, you should clone the quality profile and you should be able to activate more rules, change rule severity and create more custom rules from the existing templates.

For more information about Scalastyle rules, please consult the upstream documentation.

Set-up

Download the latest release jar into your SonarQube plugins folder /opt/sonarqube/extensions/plugins and restart SonarQube either using the update center or manually.

For an out-of-the-box setup, you can use my docker-compose recipe or a docker image with SonarQube LTS which contains bundled sonar-scala and arthepsy/sonar-scala-extra (Scapegoat) plugins. Please see mwz/sonar-scala-docker for more details.

For automating the analysis of your Scala projects, check out my sbt plugin mwz/sbt-sonar.

Sonar-scanner properties

The plugin exposes the following properties which can be passed to sonar-scanner when running an analysis:

  • sonar.sources - Scala source directory relative to the root of your project (usually src/main/scala)
  • sonar.scala.version (optional) - defines the version of Scala used in your project (defaults to 2.11.0)
  • sonar.scala.scoverage.reportPath (optional) - relative path to the scoverage report (defaults to target/scala-${sonar.scala.version}/scoverage-report/scoverage.xml)

See an example usage:

sonar-scanner -Dsonar.projectName=test \
              -Dsonar.projectKey=test \
              -Dsonar.sources=src/main/scala \
              -Dsonar.sourceEncoding=UTF-8 \
              -Dsonar.scala.version=2.12.5 \
              -Dsonar.scoverage.reportPath=target/scala-2.12/scoverage-report/scoverage.xml

Development

To build the project from sources, run the assembly task in sbt shell and the jar assembled with all of the dependencies required by this plugin should be created in the target/scala-2.12 directory.

To debug the plugin, export the following environment variable before running sonar-scanner:

export SONAR_SCANNER_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"

Once you've done that, sonnar-scanner should display the following message Listening for transport dt_socket at address: 8000. You can now attach your IDE to the process on port 8000, set breakpoints and debug the code.

Credits

This project is a continuation of sonar-scala plugin, which was originally developed by Sagacify and integrates code from two other SonarQube plugins Sonar Scalastyle Plugin and Sonar Scoverage Plugin.

Many other projects have been used as an inspiration, here is a list of the main ones:

Changelog

For a list of changes and releases, please see CHANGELOG.

License

The project is licensed under the GNU LGPL v3. See the LICENSE file for more details.

About

SonarQube plugin for static code analysis of Scala projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%