jslint

Maven plugins for javascript

Javascript code can be tough to maintain. I am looking for tools that will help me ensure a reasonable quality level. So far I have found JsUNit, a very nice unit test framework for javascript. Tests can be run automatically from ant on any browser available. I have not found yet some javascript equivalent of PMD, checkstyle, Findbug... ...

Is there an offline version of JSLint for Windows?

I would like to check my JavaScript files without going to JSLint web site. Is there a desktop version of this tool for Windows? ...

How can I set globals to JSLint to ignore for a whole set of files?

I'd like to run JSLint4Java as part of my build process. I have about 1000 JS files in a library, and don't really want to add a /*globals foo, bar, baz */ header to each of them -- especially since many of them are from an external library (Dojo). If I don't add the header, though, JSLint complains about the same five globals on ne...

Why should you not use Number as a constructor?

I entered this statement in JSLint: var number = new Number(3); And received the following message: Do not use Number as a constructor. Why is that? The statement is creating a number object, not a primitive value, so I don't see why using new is a problem. EDIT: Thanks for all the responses. They've got me thinking further, so...

Getting a JSLint warning concerning labels in Javascript

In my javascript I have this loopDeLoop: while (foo !== bar) { switch (fubar) { case reallyFubar: if (anotherFoo == anotherBar) { break loopDeLoop; } break; default: break; ...

JavaScript: 'Disallow leading _ in identifiers' as an option in JSLint

I have just started writing my own JavaScript Framework (just for the learning experience), and have prefixed some private members with a _, like such: var _isFireBugEnabled = function () { return (window.console && window.console.firebug); }; When I ran my code against Crockford's JSLint (as always), with Recommended Options on, ...

Jslint "Line breaking error"

JSLint validation of this snippet 1: function foo() {} 2: 3: foo(1 4: ); 5: 6: foo( 7: ); gives this error: Error: Problem at line 3 character 5: Line breaking error ')'. foo(1 Is this a JSLint bug? ...

JSLint (CLI): options?

I'm running JSLint's Rhino version from the Ubuntu command line like so: $ rhino jslint.js myScript.js While the web interface offers various options, I couldn't figure out how to invoke those via the command line. Am I overlooking anything in the documentation? ...

JSLint: control comments (selective ignore)

Does JSLint have anything like JavaScript Lint's control comments (e.g. /*jsl:fallthru*/) to make it ignore certain passages? ...

JSLint: Using a function before it's defined error

I'm using JSLint to verify most of my external Javascript files, but the largest amount of errors I'm getting is from functions being used before they're defined. Is this really an issue I should worry about? It seems FF,IE7,Chrome don't care. Functions like the popular init() which I use often, normally stick at the top as that makes ...

What is the reason behind JSLint saying there are "too many var statements"

JSLint (with the onevar flag turned on) is flagging some javascript code that I have with the following: Problem at line 5 character 15: Too many var statements. I am happy to fix these errors, but I'd like to know, am I doing it for performance or because it is just a bad practice and has a greater potential to introduce bugs in my ja...

Is JS lint available for offline use?

I'd like to use JSLint but am wary of tools that have access to my unfiltered source-code. Is there an offline version or is there another similar tool that does "lint error checking" for JavaScript offline? Edit: One with a GUI / shows you a styled list of errors, instead of command line? ...

What's wrong with var x = new Array();

In JSLint, it warns that var x = new Array(); (That's not a real variable name) should be var result = []; What is wrong with the 1st syntax? What's the reasoning behind the suggestion? ...

Why avoid increment ("++") and decrement ("--") operators in JavaScript?

I'm a big fan of Douglas Crockford's writing on JavaScript, particularly his book JavaScript: The Good Parts. It's made me a better JavaScript programmer and a better programmer in general. One of his tips for his jslint tool is this : ++ and -- The ++ (increment) and -- (decrement) operators have been known to contribute to bad...

Using JSLint in Notepad++

I have seen other text editors use extensions to allow syntax checkers such as JSLint, is this possible with Notepad++? ...

What is array literal notation in javascript and when should you use it?

JSLint is giving me this error: Problem at line 11 character 33: Use the array literal notation []. var myArray = new Array(); What is array literal notation and why does it want me to use it instead? It shows here that new Array(); should work fine... is there something I'm missing? ...

How to turn off JSLint indentation warnings?

I find that JSLint produces lots of warnings of the form: Expected 'foo' to have an indentation at X instead at Y. The JSLint options documentation describes an indent option that recognizes a numerical value representing the amount of space for each level of indentation. This option allows me to say things like use 2 spaces per level...

Does JSLint improve your Javascript coding?

Douglas Crockford says: JavaScript is a sloppy language, but inside it there is an elegant, better language. JSLint helps you to program in that better language and to avoid most of the slop. Do those programmers who use JSLint on a regular basis have the same opinion? ...

What does "use strict" do in javascript, and what is the reasoning behind it?

Recently I ran some of my javascript code through Crockford's JSLint, and it gave the following error: Problem at line 1 character 1: Missing "use strict" statement. Doing some searching, I realized that some people add "use strict"; into their javascript code. And once I added the statement, the error stopped appearing. Unfort...

JSLint's issue with 'window' as a global variable

So I'm using JSLint to try and detect errors. I turn some options off I don't like, but I don't see any way to enable being able to use the window global variable. Well there is the Yahoo Widget option, but that's overkill. What's the deal with using 'window', why would jslint say that is causing errors? ...