Features
| Feature | Screenshot |
|---|---|
| Static code analysis with JSLint | |
| Unit test and code coverage reports with JsTestDriver | |
Code metrics:
|
Version information
Plugin | jstd-maven-plugin | |
|---|---|---|
0.3 | 1.4.6 | |
0.4 | 1.4.6 | 1.3.2.5 |
Usage & Installation
Installation
- Install JavaScript plugin through Update Center
- Restart Sonar
Analysis with Maven
Create a maven pom for your project and run "mvn sonar:sonar" to run analysis and import JsTestDriver results
Sample JavaScript project analysis with Maven
Checkout http://javascript-plugin-for-sonar.googlecode.com/svn/trunk/sample
Update <browser> in pom.xml to point to browser where JavaScript unit tests should be run
- Run "mvn test" to execute JsTestDriver unit tests and gather code coverage statistics
- Run "mvn sonar:sonar" to analyse JavaScript code and import unit test results
Analysis with simple Java runner
- Download latest version of Simple Java Runner
- Create sonar-project.properties file for your project
Sample JavaScript project analysis with Simple Java Runner
Checkout https://javascript-plugin-for-sonar.googlecode.com/svn/trunk/sample-simple-runner
Change "<base_dir>" placeholders to actual path in sample JsTestDriver coverage file "jstestdriver/jsTestDriver.conf-coverage.dat"
- Run "sonar-runner"
Configuration
System wide/Project wide settings
Setting | Key | Corresponding parameter for JSLint |
|---|---|---|
File suffixes | sonar.javascript.file.suffixes |
|
Assume a browser | sonar.javascript.lslint.browser | browser |
Assume console, alert, ... | sonar.javascript.lslint.devel | devel |
Assume a Yahoo Widget | sonar.javascript.lslint.widget | widget |
Assume Windows | sonar.javascript.lslint.windows | windows |
Assume Rhino | sonar.javascript.lslint.rhino | rhino |
Safe Subset | sonar.javascript.lslint.safe | safe |
Predefined variables | sonar.javascript.lslint.predef | predef |
Maximum number of errors | sonar.javascript.lslint.maxerr | maxerr (default value: 50) |
| JsTestDriver Output Folder | sonar.javascript.lslint.jstestdriverfolder | Folder where JsTestDriver unit test and code coverage reports are stored |
Rules
Rule | Corresponding parameter for JSLint |
|---|---|
ADsafe rules should be enforced. See http://www.ADsafe.org | adsafe |
Allow one var statement per function | onevar |
Do Not Tolerate debugger statements | !debug |
Do Not Tolerate eval | !evil |
Do Not Tolerate sloppy line breaking | !laxbreak |
Do Not Tolerate unfiltered for in | !forin |
Do Not Tolerate inefficient subscripting | !sub |
Do Not Tolerate CSS workarounds | !css |
Do Not Tolerate HTML case | !cap |
Do Not Tolerate HTML event handlers | !on |
Do Not Tolerate HTML fragments | !fragments |
Do Not Tolerate ES5 syntax | !es5 |
Allow one var statement per function | onevar |
Disallow undefined variables (has parameter "Predefined ( , separated)") | undef: true, predef:<set value> |
Disallow dangling _ in identifiers | nomen |
Disallow == and != | eqeqeq |
Disallow ++ and – | plusplus |
Disallow bitwise operators | bitwise |
Disallow insecure . and [^...] in /RegExp/ | regexp |
Require Initial Caps for constructors | newcap |
Require parens around immediate invocations | immed |
Require "use strict"; | strict |
Maximum line length | maxlen |
Strict white space (has parameter "Strict white space indentation") | white:true, indent:<set value> |
Unsafe character. |
|
Use the array literal notation []. |
|
Use the object literal notation {}. |
|
Missing semicolon. |
|
Mixed spaces and tabs. |
|
Other Rules |
|
Unused names |
|
Do not use wrapper forms |
|
Cyclomatic complexity (has parameter "maximum threshold allowed. Default is 10." |
|
- parameters marked with ! are set if corresponding rule is not enabled
- rules that do not have parameter can not do not have special parameter in JSLint
Plugin Architecture
Code Analysis
JSLint as Javascript static analysis tool. Integrated through jslint4java
Unit Tests and Code Coverage Reports
Unit test and code coverage reports produced by JsTestDriver. Integrated through jstd-maven-plugin.
Code Duplication
For duplication detection plugin uses CPD with ANTLR Lexer generated from ECMAScript Grammar
Cyclomatic complexity
ANTLR based AST generated with ECMAScript Grammar used to count branching statements
Changelog
| Release 0.4 (5 issues) | |||||
|---|---|---|---|---|---|
| Type | Key | Summary | Priority | Status | Resolution |
|
|
SONARPLUGINS-1625 | NullPointer on loading test file |
|
|
Fixed |
|
|
SONARPLUGINS-1587 | Support of JsTestDriver unit test execution and code coverage reports should be added |
|
|
Fixed |
|
|
SONARPLUGINS-1319 | Doesn't work with SCM Plugin |
|
|
Fixed |
|
|
SONARPLUGINS-1295 | Cannot specify sonar.javascript.lslint.predef in POM |
|
|
Fixed |
|
|
SONARPLUGINS-1139 | Cannot define multiple predefined variables |
|
|
Fixed |
| Release 0.3 (1 issues) | |||||
|---|---|---|---|---|---|
| Type | Key | Summary | Priority | Status | Resolution |
|
|
SONARPLUGINS-1006 | Migrate JavaScript plugin from code.google.com to Codehaus |
|
|
Fixed |
Roadmap Ideas
- Update to latest jslint4java version
- Add support for Jasmine
- Add support for JSHint




