The JavaScript Code Quality Tool
See all
Members (704)
Douglas Crockford's profile photo
Paul Crowder's profile photo
Eugenio Gonzato's profile photo
William Malone's profile photo
Juliano Lazzarotto's profile photo
Bhavik Makwana's profile photo
Pablo Garcia's profile photo
Arvind verma's profile photo
Михаил Шестаков's profile photo
Oliver Guether's profile photo
WebmasterUM Guilherme's profile photo
Nick Newman's profile photo
Paul Wilkins's profile photo
DulowKaotic DulowKaoticCHECKTHIS's profile photo
Allen Chen's profile photo
Anton Burger's profile photo
Darrell Little's profile photo
Shravan Kumar Kasagoni's profile photo
psp i's profile photo
Harish Ramarao's profile photo
Rob Hughes's profile photo
Jeff Dickens's profile photo
Mariane Machado's profile photo
Carolyn Stephany Ulfe Ureña's profile photo

Stream

 
/*global $ */
/*jslint browser */

$(function () {
$();
});

The Expected ' "use strict"; ' warning is missing.
1
Douglas Crockford's profile photo
 
Thanks. Please try it now.
Add a comment...

raal Bvv

Discussion  - 
 
Hi, how should this simple example be rewritten to avoid out of scope error ? http://pastie.org/pastes/10847770/text
/*jslint es6, maxerr: 200, browser, devel, fudge, maxlen: 100, node */ const someUtility = (function () { "use strict"; const result = []; const dealWithTheAtom = function (atom) { //do something with the atom //for instance result.push(atom); }; const moderatorFunction = function (something) { ...
1
Peter's profile photoraal Bvv's profile photo
7 comments
 
I wonder what +Douglas Crockford would do. 
Add a comment...
 
Bad module name. The following line produces an error on JSLint:

/*jslint es6 */
import Cycle from '@cycle/core';

-> Bad module name '@cycle/core'

npm uses the @ sign for name spacing modules which I think is a good idea, name spacing of modules, for the @ I am not so sure. Any chance of accepting this in JSLint?
2
Nicola Squartini's profile photo
5 comments
 
Thanks!
Add a comment...
 
Destructuring on import statements. Is there a reason that jslint does not like the following:

/*jslint es6 */
import {a, b} from 'module';

Expected an identifier and instead saw '{'.
1
Νίκος Καλογρίδης's profile photoDouglas Crockford's profile photo
8 comments
 
Please try it now.
Add a comment...

Harry Whitfield

Discussion  - 
 
On JSLint edition 2016-05-05,
var newTimeStamp = new Date().getTime() / 1000;

gives

Expected 'new' before 'Date'. line 0 column 23
var newTimeStamp = new Date().getTime() / 1000;
Unexpected 'new'. line 0 column 27
var newTimeStamp = new Date().getTime() / 1000;
1
Douglas Crockford's profile photoHarry Whitfield's profile photo
4 comments
 
+Douglas Crockford Something more general would probably be more useful because similar error messages can occur with other examples.

Perhaps, something like "Expected 'new Date()' in parens and saw 'new Date().getTime()'".

Here is an artificial case that produces a similar confusing error message:

/*jslint this */

function Epoch() {
"use strict";
var date = new Date();
this.now = date.getTime() / 1000;
}

var timeStamp = new Epoch().now;

In this case the message could be "Expected 'new Epoch()' in parens and saw ' new Epoch().now'".

The error message should ideally express what JSLint is objecting to.
Add a comment...

Simon Shepard

Discussion  - 
 
I just saw this article : https://www.cigital.com/blog/node-js-socket-io/
The offending piece of code is : 
this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? null : opts.rejectUnauthorized;
is there anyway JSlint could have prevented this stupidity?
1
Douglas Crockford's profile photo
 
If you have a specific proposal, I will consider it.

The stupidity, according to the article, was not the statement you identified, but a lack of intelligent defensiveness in the implementation of TLS.
Add a comment...

Ruffin Bailey

Discussion  - 
 
Is the Unexpected '.'. warning for a method call after a parenthetical intentional?

Snippet from an SO question:
    var hours = parseFloat($hours.val());
    var rate = parseFloat($rate.val());
    var total;

    if (!isNaN(hours) && !isNaN(rate)) {
        // This throws the error.
        total = (rate * hours).toFixed(2);
    }

Anything with this sort of construction (operator or no) will throw a warning, eg... 
    var moreSpam = ("spam" + "spamspam").split("s");
    var loveSpam = ("spam").split("s");

I can understand the last, but the others do not seem to preclude readability, and the original use of toFixed() seems expedient at worst.
1
Nicola Fankhauser's profile photoRyc O'Chet's profile photo
5 comments
 
This is one of the major reasons to switch to Typescript - JSLint / JSHint help catch a lot of accidental errors (and a lot of the suggestions for good coding style make a lot of sense, just that some like this don't), but even if just using plain JS with the .ts extension it catches and prevents significantly more (adding types to function arguments is even better) - not trying to be evangelical here, but my productivity and quality at work has jumped significantly since switching to it...
Add a comment...

Mathias Nater

Discussion  - 
 
In the following construct JSLint warns about "Redefinition of 'i'":

function outer1() {
"use strict";
var i;
function inner1() {
var i;
}
}

That's helpfull.


But there's no warning in the following construct:

function outer2() {
"use strict";
var i = 43;
function inner2(i) {
...
}
}

Why? This could cause similar issues.

1
Douglas Crockford's profile photo
 
People tend to pay more attention to their parameter names, since they are sometimes part of the public documentation. Variable names are strictly private, and so get less thought.
Add a comment...

Fedge No

Discussion  - 
 
Found a bug. Running this through JSLint with the options "a browser" and "this" still produces an error, "Expected 'new' before 'Asset'." There is 'new' before 'Asset'.

I initially had it assigning the Asset object to a variable and that produced the error as well so I tried changing it to just a return and it made no difference.

Here's the script. Just writing the last little section as a single function didn't seem to produce the error.

https://cdnpoli.net/assets/common.js


1
Nathan Ho's profile photoFedge No's profile photo
5 comments
 
Thanks. I didn't know if you could do that with constructors. I guess in the end they are just functions, though.
Add a comment...
 
just got an error from JSLint with a regex that seems to be totally ok:

return html.replace(/<(\w*)[^>]\s(?:href=|src=)("|')?(https?:\/\/)?(\/\/)?([^\/\?\s]+\.+[^\/\?\s]+[^\/\?\s]\/)?(\.\/[\.\/])?([^\s])(\2)[^>]*>/ig, modifyPath);

complains with a:
Unexpected '2' after '\'.

\2 references the huntgroup 2 so this should be ok here. Anything that I have missed? Or a switch that makes JSlint say, this is ok here?

1
Douglas Crockford's profile photo
 
No. JSLint has seen too many tragic accidents due to this feature. I recommend that you expand the regexp.
Add a comment...

About this community

This group is for discussion of JSLint, including feature requests, complaints, update announcements, and testimonials.
 
In ES6, some modules may not export anything and be imported only for thier side effects. ECMAScript (http://www.ecma-international.org/ecma-262/6.0/#sec-imports) specifies two forms for this case:

import 'module_name';

import {} from 'module_name';

Could JSLint support the first form of import statement?
Thanks.

Ecma International. Rue du Rhone 114. CH-1204 Geneva. Tel: +41 22 849 6000. Fax: +41 22 849 6001. Web: http://www.ecma-international.org. COPYRIGHT NOTICE. © 2015 Ecma International. This document may be copied, published and distributed to others, and certain derivative works of it may be ...
1
Douglas Crockford's profile photoNicola Squartini's profile photo
7 comments
 
Thanks a lot!
Add a comment...

raal Bvv

Discussion  - 
 
why do I get this error : Unexpected '`'.
http://pastie.org/pastes/10847511/text
/*jslint es6, maxerr: 200, browser, devel, fudge, maxlen: 100, node */ const thing = (function () { "use strict"; const list1 = []; const function1 = function (a, b, c) { list1[`${a}-${b}`] = c; }; const function2 = function (d) { return list1[d]; }; return Object.freeze({ function1, function2 } ...
1
Douglas Crockford's profile photoraal Bvv's profile photo
2 comments
 
The error is gone, thanks.
Add a comment...

Ben Pardo

Discussion  - 
 
What are people's thoughts on React.js? I feel very mixed about any further glorification of XML.
1
Josef Jelinek's profile photo
 
You are referring to JSX, which is not a necessary part of React. Many people (citation needed) use just the JS part of React and do not complicate their tool chain with JSX compilers etc. So I think you are asking more about "what are people's thoughts on JSX parts of react", which has not much to do with JS.
Add a comment...
 
/*jslint
browser
*/
/*global
google
*/
(function () {
'use strict';
return new google.maps.places.Autocomplete();
}());

jslint complains with:
Expected 'new' before '.'.
return new google.maps.places.Autocomplete();

if I remove the ".places" part of the statement it seems to not produce that error. Am I missing something or is this a bug?
1
Евгений Орехов (Evgeny Orekhov)'s profile photoDouglas Crockford's profile photo
3 comments
 
Thanks. Please try it now.
Add a comment...

Harry Whitfield

Discussion  - 
 
/*jslint this */
/*property
    Item, Movie, Players, QTControl, Stop, createObject, player, prototype,
    quit
*/
"use strict";
var COM;    // Windows COM object
function QT() {  // Constructor of QT object
    this.player = COM.createObject("QuickTimePlayerLib.QuickTimePlayerApp.1");
}
QT.prototype.quit = function () {
    this.player.Players.Item(1).QTControl.Movie.Stop();
    this.player = null;
};
/*
gives

Expected 'new' before '.'.  line 12 column 16
    this.player.Players.Item(1).QTControl.Movie.Stop();
Expected 'new' before '.'.  line 12 column 42
    this.player.Players.Item(1).QTControl.Movie.Stop();

The capitalized names are defined in the QuickTimePlayerLib
over which I have no control.
*/
1
Harry Whitfield's profile photoNathan Ho's profile photo
5 comments
 
+Harry Whitfield I can tell that QuickTime has provided you a pretty crappy API -- not just poor capitalization, but the fact that you have to write long chains like "player.Players.Item(1).QTControl.Movie.Stop()".

This is a sign that you should write a wrapper that goes between your code and QuickTime's. This kills two birds with one stone -- both capitalization and the awkward API. I would approach this by writing a function that attaches helper methods:

function better_api(qt_app) {
qt_app.stop = function () {
qt_app.Players.Item(1).QTControl.Movie.Stop();
};
return qt_app;
}

Make this wrapper minimal and don't show it to JSLint. Your main code becomes:

function QT() {
this.player = COM.createObject("QuickTimePlayerLib.QuickTimePlayerApp.1");
better_api(this.player);
}

QT.prototype.quit = function () {
this.player.stop();
this.player = null;
};

which is JSLint-friendly.

It is up to you to decide whether this workaround is worth it. If your program is pretty small, the above strikes me as excessive, and in that case you might as well go without JSLint.
Add a comment...
 
/*jslint es6 */
function f0({a}) {
"use strict";
return a;
}
function f1(a = 1) {
"use strict";
return a;
}
function f2(...a) {
"use strict";
return a;
}

The latest Chrome and Node.js throw
"SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list"
for these functions.

I googled and found this https://github.com/rwaldron/tc39-notes/blob/master/es7/2015-07/july-29.md#conclusionresolution

I tried to look for this topic in the Language Specification but found it too cryptic, I would need more time and effort to get to the bottom of this.

Do you know anything about this topic?
Should JSLint give warnings for the above code?
1
Add a comment...

Austin Cheney

Discussion  - 
 
I prefer to declare my variables in a list, such as:

    var someting = "asdf",
        other = "other string";

I get a warning: Expected ';' and instead saw ','.

What is the preferred means of declaring variables without having to use multiple var keywords per function?
1
Austin Cheney's profile photoStéphane Trebel's profile photo
6 comments
 
Wouldn't it also make for prettier diffs when you just add a variable declaration at the end of the declaration list ?
I mean, I'm not the only one forgetting to turn a semi-colon into a comma, am I ?
Add a comment...

James Long

Discussion  - 
 
Should the code below produce an out_of_scope_a error for the variable o? Currently it does not and I don't know whether that was a deliberate choice or a case that no-one has spotted yet.

function makeObject() {

    "use strict";

    var obj = {};

    function doOne(arg) {
        arg();
        return obj;
    }

    function doTwo() {
        return obj;
    }

    obj.doOne = doOne;
    obj.doTwo = doTwo;

    return obj;

}

var o = makeObject().doOne(function () {
    o.doTwo();
});
1
Douglas Crockford's profile photoJames Long's profile photo
2 comments
 
The truth is that I don't know. This particular example is somewhat contrived - I noticed it when I bound an event to a jQuery object so the variable would exist by the time the function is executed.

This situation seems to me like it should have thrown an error so I was mainly querying whether others agreed. I don't know if there are any patterns where this would cause actual issues so if you feel that it's an edge case and no one else thinks it's problematic then ill let it go. 
Add a comment...
 
JSLint should warn that Object.assign() is an ES6 feature.
1
Евгений Орехов (Evgeny Orekhov)'s profile photoFedge No's profile photo
2 comments
 
Don't forget to completely rewrite your polyfills so JSLint likes them too :P
Add a comment...

Harry Whitfield

Discussion  - 
 
BUG?
"use strict";
var operator = {};
operator.data = "*";
var roman = {};
roman.data = "MDC";
var decimal = {};
decimal.data = "123.456";
var print;

function processOperator(item, legend) {
    switch (item) {
    case 27:    // Backspace
        roman.data = roman.data.substring(0, roman.data.length - 1);
        return;
    case 28:    // Return
        decimal.data = decimal.data.substring(0, decimal.data.length - 1);
        return;
    default:
        break;
    }
    operator.data = legend;
}

processOperator(23, "+");
print(operator.data);       // prints "+"

Gives

Unreachable '='.
    operator.data = legend;
1
Douglas Crockford's profile photoHarry Whitfield's profile photo
8 comments
 
+Douglas Crockford You were very quick to reply! I'd just come to the same thought myself and edited my previous reply.
Add a comment...