Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »



Name

JavaScript

Latest version

0.3-SNAPSHOT ( 21 Mar 2011 )

Requires Sonar version

2.3 or higher

Download

0.3-SNAPSHOT

License

GNU LGPL 3

Developers

Eriks Nukis

Issue tracker

http://jira.codehaus.org/browse/SONARPLUGINS/component/14683

Sources

https://svn.codehaus.org/sonar-plugins/trunk/javascript

Table of Content

Features

The plugin provides Javascript static code analysis with JSLint

The following metrics are supported:

  • sizing (files, lines of code)
  • duplication
  • comments
  • cyclomatic complexity (function complexity, file complexity, complexity density)

The plugin scans the following files by default: .js. The file extensions are configurable.

The plugin imports the source code in Sonar, calculates measurements and scans the code for violations, duplications. The checks are configurable in the Sonar rules repository.

Version information

Plugin

jslint4java

0.3

1.4.6

Usage & Installation

Installation

  1. Copy the jar into /extensions/plugins/ directory
  2. Restart Sonar Web server

Analysis

Create a maven pom for your project. Set the following properties:

  • sonar.language: js
  • sonar.dynamicAnalysis: false
Sample pom.xml

Quick analysis

For an existing Javascript project that is built/packaged with Maven, you might start an analysis by the following command:

You may set the property sonar.branch to make sure the web analysis will be reported in sonar under another project name, e.g. -Dsonar.branch=Javascript.

Please note you can run sonar analysis for an artefact in only one language http://jira.codehaus.org/browse/SONAR-926 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.

Configuration

System wide/Project wide settings

Setting

Corresponding parameter for JSLint

Assume a browser

browser

Assume console, alert, ...

devel

Assume a Yahoo Widget

widget

Assume Windows

windows

Assume Rhino

rhino

Safe Subset

safe

Maximum number of errors

maxerr (default value: 50)

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

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

Loading

Release 0.3 (${entries.size()} issues)

Type Key Summary Priority Status Resolution

Roadmap ideas

  • No labels