The plugin provides static code analysis of web files within Sonar. Currently JSP and JSF are supported. Some initial support is provided for Ruby templating (erb files).
The following metrics are supported:
- sizing (files, lines of code)
- rules compliancy
The plugin scans the following files by default: .xhtml, .jspf, .jsp. The file extensions are configurable.
The plugin imports the source code in Sonar, calculates measurements and scans the code for violations, duplications and complexity. The checks are configurable in the Sonar rules repository.
Usage & Installation
- Copy the jar into /extensions/plugins/ directory
- Restart Sonar Web server
Create a maven pom for your project. Set the following properties:
- sonar.language: web
- sonar.web.sourceDirectory: [folder of the web files]
- sonar.dynamicAnalysis: false
Sample pom file:
For an existing maven project, you might start an analysis by the following command:
Please note you can run sonar analysis for an artefact in only one language (SONAR-926). So you cannot run a web analysis and a java analysis on the same maven project. The fix is to make a separate maven pom for the web project with a different name.
There are about 20 checks in the library. Please read the documentation of the checks on the page Web Rules Library.
The ruleset is inspired on the following standards and guidelines:
A complete explanation of the available checks is given here .
Complexity of the web page is measured by counting the decision tags (such as if and forEach) and boolean operators in expressions ("&&" and "||"), plus one for the body of the document. It is a measure of the minimum number possible paths to render the page.
The decision tags and the operators are configurable. For details see rules library
Duplication is counted by comparing tokens. Duplication is reported if more than a minimum amount of tokens are replicated (in the same file or another file). The default minimum tokens is set to 70.
Comments are counted by adding the lines for server side and client side comments.
The following properties of the plugin are configurable:
The plugin uses a simple tokenizer to parse the web pages. The tokenizer is based on the sonar-channel library. The output of the tokenizer is analyzed by a set of analyzers and checks. Expressions written in the Unified Expression Language (EL) are validated with JBoss EL.
No further external tools or maven plugins are being used for analyzing the code.
Release 1.0 (21 issues)
Release 0.1 (5 issues)
|SONARPLUGINS-638||New web rule : Every image should be provided with a proper alternative text||Closed||Not A Bug|
|SONARPLUGINS-628||Create a first implementation of the CodeColorizer extension point to highlight the HTML syntax in the Sonar Code Viewer||Closed||Fixed|
|SONARPLUGINS-625||Configurable file extensions||Closed||Fixed|
|SONARPLUGINS-624||WebPlugin: Alpha Release 1||Closed||Fixed|
|SONARPLUGINS-130||SONAR : JSP & HTML Analysis||Closed||Fixed|
- Run analysis directly from maven (without sonar)
- More support for WCAG, webrichtlijnen
- Enhanced validation of unified expressions (using JSFUnit?)
- Dependency analysis