The JavaScript Code Quality Tool
See all
Members (483)
Douglas Crockford's profile photo
Ben White's profile photo
Adam Moore's profile photo
Benjamin Black's profile photo
Ahmed Attyah's profile photo
Anže Matelič's profile photo
Angelos Chaidas's profile photo
Alejandro Amador's profile photo
Ben Pardo's profile photo
Anthony FLORES's profile photo
Alex Lambiris's profile photo
Ashish Raina's profile photo
Alexandr Cherednichenko's profile photo
Alexandre Morgaut's profile photo
Arvind kumar verma's profile photo
Amir Esmann's profile photo
Anas Bihi's profile photo
Anders Eknert's profile photo
Anders Sjöberg's profile photo
Andrea Giammarchi's profile photo
Bill McMilleon's profile photo
Andrew Pennebaker's profile photo
Andrew Ryan's profile photo
Andrew Whitaker's profile photo

Stream

Douglas Crockford
owner

Discussion  - 
 
Yesterday I announced a new version of JSLint for ES6. This morning it is top of the search results on Bing. It hasn't shown up on Google yet, which is surprising since I made the announcement here.
13
JavaScript Packer's profile photo
 
Can't figure out myself why some will show on Google and some don't.
Add a comment...
 
JSLint offers "plusplus": true|false to configure whether increment/decrement operators are allowed, but the online documentation neglects to mention this.

http://www.jslint.com/lint.html#options
1
Sean Kelly's profile photoChad Walker's profile photo
2 comments
 
The option is deprecated and will be removed in a future version. After that time += 1 is all that will be allowed.
Add a comment...
 
Could JSLint please offer an option, like vars, for temporarily disabling the warning to move var declarations to the top of functions?
2
Alex Howard's profile photoAndrew Pennebaker's profile photo
2 comments
 
Lol.

I don't see an option for this particular rule. I tried "vars", but that seems to affect a different rule.
Add a comment...

David Grima

Discussion  - 
 
Is it a good practice to name chainable functions of an object? For example, the first letter capitalized for chainaibles functions that return this and lower case for others.

var car = new Car();
var position = car.Start().TurnLeft().Stop().getPosition();

Do JSLint should implement such controls?
1
Daniel Langdon's profile photoDavid Grima's profile photo
8 comments
 
Is this a joke inspired by LISP programing or are you suggesting to write car.Cdr() instead of car.cdr() ? :-)
Add a comment...

Tommaso Ricci

Discussion  - 
 
Is there any way to test for messy whitespace, but allow the tab indentation instead of whitespace?

I can't find any way to check that. By default it asks me to use spaces instead of tabs and shows a lot of errors (ie. expected at column X, not column Y), and with the white: true option it will disable both the indentation and whitespace check.

I'd really love to be able to use JSLint without replacing all the tabs everytime
1
Brennan Young's profile photoAlex Howard's profile photo
7 comments
 
JSLint is a tool intended for people who want to make sure their code is as close to perfect and error resistant as possible. Students new to programming simply and obviously cannot make that a reality.

That said, giving them JSLint, the bar to shoot for, will immediately teach them what is a bad practice; since it's easier to learn a good habit than it is to unlearn a bad habit I posit that it will save them some struggle down the road when their entire existence is being challenged by finding out something they have always used is a bad practice.

Moreover, as a teacher you can take the opportunity to explain to a learning student why something is being flagged as bad when they are frustrated because they don't understand.

There's also always the comment options you can put at the top of files/around functions containing "jslint white:true".

Or, yeah, there's also JSHint.. that's written for people who can't handle the truth (yet).
Add a comment...

Saravana Kumar

Discussion  - 
 
hi all, {
    "asi": true
}
in $HOME/.jslintrc  doesn't stop the missing semicolon warnings. is that how it works in jslint?
1
Douglas Crockford's profile photo
 
No. The way it works with JSLint is that you should fix your code.
Add a comment...
 
Is there a way to get the current version of JSLint to check JavaScript inside an HTML document?
1
Douglas Crockford's profile photoAlbert Wiersch's profile photo
3 comments
 
Thank you. I suspected as much but wanted to make sure. The older version of JSLint I was using still included the HTML parser so I am modifying my application to no longer use JSLint on HTML documents.
Add a comment...

Albert Wiersch

Discussion  - 
 
CSE HTML Validator uses and older version of JSLint and I'd like to update it but last I checked it doesn't work with cscript.exe and Windows Script Host, apparently because of the non-compliant Microsoft script engine. Is this still the case? What is the best way to go about getting the latest version of JSLint to work with cscript.exe or the best alternative? I'd rather update JSLint than continue to use the older version.
1
Sam Mikes's profile photoBen Quarmby's profile photo
7 comments
 
The lightest solution as far as distributed file size goes is to use .NET and the WebBrowser control. It's possible to use that to inject and run JSLint with a very small footprint.

However, it requires IE9+ to be installed on the target machine, and to force strict document mode. Otherwise it falls back to the old JScript engine which is incompatible with JSLint.
Add a comment...
 
JSLint and Chrome 40 don't agree

if my code is this:
if (typeof c === "undefined") { return; }

then JSLint complains:
Unexpected 'typeof'. Use '===' to compare directly with undefined.

if I change it to this:
if (c === undefined) { return; }

then Chrome 40 complains:
Uncaught ReferenceError: c is not defined

So which is correct ?
1
Ben Quarmby's profile photo
11 comments
 
It is also safe to compare the type of c to what you want it to be (i.e. an object) rather than what you don't want it to be (undefined). For example:

if (typeof c !== 'object') {
    // handle lack of global c object
}
Add a comment...

David Grima

Discussion  - 
 
Question about global declarations

1. JSLint Error: '$' was used before it was defined. > It's true.

/*jslint browser: true */
(function () {
    'use strict';
    $.DoSomeThing();
}());

2. JSLint Error: '$' was used before it was defined. > It's true.

/*jslint browser: true */
(function ($) {
    'use strict';
    $.DoSomeThing();
}($));

3. JSLint Ok > By JSLint design

/*jslint browser: true */
/*global $ */
(function () {
    'use strict';
    $.DoSomeThing();
}());

4. JSLint Ok > I think it's the best pattern

/*jslint browser: true */
(function ($) {
    'use strict';
    $.DoSomeThing();
}(window.jQuery));

5. JSLint Ok: > I think it's evil because of $ conflict

/*jslint browser: true */
var $ = window.jQuery;
(function () {
    'use strict';
    $.DoSomeThing();
}());

What do you think about the 3., 4. and 5. patterns?
1
Ben Quarmby's profile photo
 
Possibly splitting hairs here :)

If jQuery is being used throughout the app (preferably in no-conflict mode), then it's a known global and there's no reason to avoid telling JSLint about it. In fact, JSLint is more likely to catch human error (typos) if the global variable is used directly rather than as a property of window.

App specific JSLint options are better in a shared location rather than inline with the script if that's possible.

I find that passing arguments to an IIFE is hard to maintain. The longer the module gets, the further away the real values are. Creating a local variable as an alias at the top is very similar to a parameter in terms of scope, and keeps everything much closer together.

So I would suggest the following:

// JSLint options set elsewhere
(function () {
    'use strict';

    var $ = jQuery;

    $.DoSomeThing();
}());
Add a comment...

About this community

This group is for discussion of JSLint, including feature requests, complaints, update announcements, and testimonials.
 
Could JSLint only warn once for missing "use strict"; per file, instead of every function?
1
Jonas Trollvik's profile photoChad Walker's profile photo
2 comments
 
or put "use strict"; at the top of the file. You said in another post that you were mainly working in node; at my company we put 'use strict'; at the top of every file (and every file is run through jslint before it can be merged).
Add a comment...
 
How can I temporarily disable the empty block rule?

JSLint prefers "use strict";

While JSHint prefers (function() { "use strict"; })();

triggering an "Empty block" warning in JSLint.

(I would like to use both linters on my codebase.)
1
Alex Howard's profile photoDenford Berriman's profile photo
14 comments
 
+Andrew Pennebaker  Read "JavaScript: the good parts" Then you might avoid a bunch of errors in the first place.
Add a comment...
 
Could JSLint please continue scanning when a var could be moved to the top of functions? I want to see all linter warnings, not just the first ones found.
2
Andrew Pennebaker's profile photoDavid Ernst's profile photo
3 comments
 
Likewise, especially when inheriting code from others.
Add a comment...

Brian McMillin

Discussion  - 
 
Since Tomasso raised an issue regarding the Messy White Space warning, I thought I would mention a suggestion I have been toying with for a while.

How about an option (or perhaps even default behavior) which does one simple thing:

Suppress the Messy White Space warning IFF the whitespace ends on a "nice" column, such as multiple of eight.

This will allow aesthetic columnization, such as data in a table and will standardize those columns while preserving the warnings that we all know and love for other cases.

The reason that I think it might be possible for this to be default behavior (and not introduce another confusing option) is a probabilistic one: There would only be a one-in-eight possibility that a true Messy White Space would be unreported.  Would this be helpful enough to justify the change?
2
Alex Howard's profile photoTommaso Ricci's profile photo
8 comments
 
Wouldn't it be simpler to allow the choice to use X spaces or 1 tab per indent (with config options)? Then you will get errors just if you mix tab and spaces, or you don't type a correct multiple of X spaces
Add a comment...

Alex Howard

Discussion  - 
 
I find myself going absolutely crazy debating with the unenlightened about things like why all variables need to be declared at the top of scope, or why keywords should have a space between them and the parentheses.. I don't know how you do it.. You must feel like Bill Nye debating climate change. Where do I send donations?
10
Alex Howard's profile photo
9 comments
 
+Ben Quarmby I wasn't being facetious! I don't know how I missed that... Donation submitted!
Add a comment...
 
If you use Windows and would like to test my application's JSLint integration with JS files then please email me at support@htmlvalidator.com. It now uses Node.js and the latest version of JSLint.
1
Albert Wiersch's profile photo
 
In case anyone is interested, CSE HTML Validator v15.02 has been released and includes the latest version of JSLint. It is now run using Node.js which is a big change from previous versions. https://www.htmlvalidator.com/ if you want to try it.
Add a comment...

Ben Quarmby

Discussion  - 
 
I realize it's impossible for JSLint to warn against every form of stupidity, but perhaps the following defect is detectable? The value variable is technically assigned and used within the body of the function, but not before being used in a logic block.

var GLOBAL = {
    value: true,

    method: function () {
        'use strict';

        var value;

        if (value) {
            value = this.value;

            return value;
        }
    }
};
1
Add a comment...
 
JSLint does not appear to be supporting ES6 template strings yet.

var a = `asdf`;

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings

My question, which I cannot find anywhere, is what happens when template strings are nested? Is such an accepted behavior or an error?

var a = `asdf ${ c + d } blah blah ${ e + `qwerqwer` + f } zxcv`;
Template strings are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.
1
Douglas Crockford's profile photo
 
JSLint does not recognize any of ES6 yet. ES6 is not even finished yet. If we are lucky it will be published in June.
Add a comment...

Douglas Crockford
owner

Discussion  - 
 
Should there be a warning on top level loops, that is loops that are not within a function?

Similarly, should there be warnings for top level switches and ifs?

Suggestion: There are a small number of features that make sense at the top level. Using any of the others is likely to be problematic. The top level should allow definition of variables and functions, trys, assignments, invocations, and ifs around the assignments and invocations. Everything else presents warnings, including loops, switches, etc.
8
Antony Scriven's profile photo
14 comments
 
Actually, I retract what I said earlier: I don't think that JSLint should set any options for Node.js, since module-level source code isn't really ES5-compliant.
Add a comment...

Chad Walker

Discussion  - 
 
At work we just ran into something like this:

    /global foo:true/
    var ct;
    ct = foo = ct;

no jslint warnings for double assignment? or an assignment on the same variable to itself? the intended code was:

    ct = foo.ct;

the developer (and reviewer) just had a brainfart
1
Douglas Crockford's profile photoBen Quarmby's profile photo
8 comments
 
Yes. Bad sample, agreed.

If I do find a convincing reason to keep multiple assignments, I'll share it.
Add a comment...