JSLint
The JavaScript Code Quality Tool
JSLint:The JavaScript Code Quality Tool jslint, the javascript code quality tool.
this file allows jslint to be run from a web browser. it can accept a source
program and analyze it without sending it over the network.
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?
Source: (StackOverflow)
What does JSLint mean by this error and how should it be rewritten?
Error: Problem at line 78 character 3: Move the invocation into the parens that contain the function:
})(jQuery);
Source: (StackOverflow)
Recently I was running some of my code through JSLint when I came up with this error. The thing I think is funny about this error though is that it automatically assumes that all == should be ===.
Does that really make any sense? I could see a lot of instances that you would not want to compare type, and I am worried that this could actually cause problems.
The word "Expected" would imply that this should be done EVERY time.....That is what does not make sense to me.
Source: (StackOverflow)
I include the statement:
"use strict";
at the beginning of most of my Javascript files.
JSLint has never before warned about this. But now it is, saying:
Use the function form of "use strict".
Does anyone know what the "function form" would be?
Source: (StackOverflow)
I ran JSLint on this JavaScript code and it said:
Problem at line 32 character 30: Missing radix parameter.
This is the code in question:
imageIndex = parseInt(id.substring(id.length - 1))-1;
What is wrong here?
Source: (StackOverflow)
I used JSLint on a JavaScript file of mine. It threw the error:
for( ind in evtListeners ) {
Problem at line 41 character 9: The body of a for in should be
wrapped in an if statement to filter unwanted
properties from the prototype.
What does this mean?
Source: (StackOverflow)
What is the best practice for that then?
Jslint explains that it "adds confusion". I don't see it really...
EDIT: The code, as requested:
var all,l,elements,e;
all = inElement.getElementsByTagName('*');
l = all.length;
elements = [];
for (e = 0; e < l; (e++))
{
if (findIn)
{
if (all[e].className.indexOf(className) > 0)
{
elements[elements.length] = all[e];
}
} else {
if (all[e].className === className)
{
elements[elements.length] = all[e];
}
}
}
Source: (StackOverflow)
Hi I have the 3 javascript files.
- jquery.js
- utility.js
- file1.js
In file1.js I have
jQuery.noConflict()
jQuery(document).ready(function($) {
// ....
});
I get an error 'jQuery' was used before it was defined.
and 'document' was used before it was defined.
How do I safely get rid of this warning.
If I do
var document = document || {};
then in my utility.js if it is used, it would be null in IE and ok in firefox.
What is the best solution to this?
Source: (StackOverflow)
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 sense to me (I like to pretend it's analogous to main()) will, according to JSLint, need to be pushed to the bottom of the file.
Source: (StackOverflow)
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?
Source: (StackOverflow)
JSLint reports Insecure '^' for the following line. Why is that? Or is it just going to complain any time I want to negate a character class?
// remove all non alphanumeric, comma and dash characters
"!$7s-gd,&j5d-a#".replace(/[^\w,\-]/g, '');
Source: (StackOverflow)
This question already has an answer here:
I know this is silly, but there's any difference between this:
(function() {
var foo = 'bar';
})();
and this?
(function() {
var foo = 'bar';
}());
JSLint tells us to Move the invocation into the parens that contain the function
, but I see no need to.
Edit: The answers are too cool. ~function
, the JSHint alternative along with jQuery's preference for (/***/)();
and Crockford's explanation! I thought I was going to just get a "they're the same thing" kind of answer.
You guys decide the best one through upvotes and I tick it.
Source: (StackOverflow)
I'm a pretty new Vim user and I've found that its learning curve is quite steep (at least for me). I just installed this vim script for JavaScriptLint error checking, which shows errors in vim's quickfix window once I save a buffer.
However, I don't know what to do next.. How do I 'scroll' through all the errors? How do I close the quickfix 'window'? How do I get it to check for errors after I've made changes to my code?
I've looked at the vim quickfix docs but the amount of commands are overwhelming and I can't seem to find what I want. Any help would be appreciated.
A side question: is there any way to have javascriptlint check for js errors for code residing in a .html file?
Thanks!
Source: (StackOverflow)
what can I do if JSLint complains about "i" being an unused variable in such a scenario:
var items = "<option selected></option>";
$.each(data, function (i, item) {
items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
});
(i, item) is the required order of parameters and I'm only using "item".
Is there any other solution than tolerating unused variables or rewriting the $.each to use the index, both solutions which I would prefer not to do?
Thanks in advance.
Update: I appreciate all the suggestions but this code is simply an example to show you what I mean and I'm interested to see a general solution, if there's any. Thanks.
Source: (StackOverflow)