Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the Eclipse Javascript formatter be set up for JSLint compliance?

I can't seem to configure the Eclipse Javascript formatting options so that it generates markup JSLint doesn't complain about - primarily whitespace settings when the "tolerate sloppy whitespace" option isn't set on JSLint. It is possible to configure this?

For example, JSLint expects function declarations to be spaced as shown:


function () {
}

function foo() {
}

but I can only get the settings to produce:


function () {
}

function foo () {
}

or


function() {
}

function foo() {
}

Alternatively is there a lightweight editor/IDE which will format my javascript code to create markup that satisfies the whims of JSLint?

like image 641
Chris Cooper Avatar asked Aug 03 '12 15:08

Chris Cooper


1 Answers

Try jshint-eclipse plugin. Also see this question asked earlier.

Quote from the JSHint page :

JSHint is a fork of JSLint, the tool written and maintained by Douglas Crockford.

The project originally started as an effort to make a more configurable version of JSLint—the one that doesn't enforce one particular coding style on its users—but then transformed into a separate static analysis tool with its own goals and ideals.

jshint-eclipse is an eclipse plugin that integrates JSHint with Eclipse.

The update site for jshint-eclipse is :
http://github.eclipsesource.com/jshint-eclipse/updates/

Update

I wanted to post some snapshots to show the effect of installing this plugin on Javascript files.

Before

Note that the Problems view is empty.

No Problems in the code

After

The JSHint plugin needs some configuration to be done after installation. This is also listed on the jshint-eclipse site :

On a project that contains JavaScript files, open the context menu and select Properties On the JSHint page, enable JSHint for this project

I did the above and enabled JSHint for *.js files like so :

enter image description here

After doing that with the same JS file as before, the Problem view begins showing errors:

enter image description here

like image 194
Ashutosh Jindal Avatar answered Sep 22 '22 10:09

Ashutosh Jindal