The JavaScript Code Quality Tool
See all
Members (570)
Douglas Crockford's profile photo
Aaron Ash's profile photo
Antony Scriven's profile photo
Andrii Trybynenko's profile photo
Andrew Pennebaker's profile photo
Adhithya Rajagopalan's profile photo
ahmd refat's profile photo
Ahmed Attyah's profile photo
Ajay Reddy's profile photo
Albert Wiersch's profile photo
Alejandro Amador's profile photo
Aleksandr Motsjonov's profile photo
Anthony FLORES's profile photo
Alex Howard's profile photo
Arild Haugstad's profile photo
Andrea Giammarchi's profile photo
Andrew Whitaker's profile photo
Alexandre Canijo's profile photo
Alexandre Morgaut's profile photo
Alfredo Delgado's profile photo
Amir Esmann's profile photo
amruta shah's profile photo
Anas Bihi's profile photo
Art Stryer's profile photo

Stream

Austin Cheney

Discussion  - 
 
Recursive functions generate a "out of scope" error.

var a = function (x) {
    "use strict";
    if (x > 1) {
        x -= 1;
        a(x);
    }
};
1
Douglas Crockford's profile photoAustin Cheney's profile photo
3 comments
 
Awesome.  Easily solved when a function has both an assignment and a name.
Add a comment...

James Long

Discussion  - 
 
I'm getting some strange errors if I tick the ES6 option with this code:

let arr = [1, 2, 3, 4, 5];
arr.forEach((number) => {
    'use strict';
    console.log(number);
});

I get the errors "Unused 'number'." and "Expected 'function' and saw '=>'." I wouldn't expect either of those (although I would expect "Undeclared 'console'.") Am i misinterpreting the fat-arrow requirements or is this a bug?
1
Nathan Ho's profile photoJames Long's profile photo
2 comments
 
Ah, that makes sense. Thanks for the response.
Add a comment...
 
I don't quite get the rules of "Wrap this regexp in parens to avoid confusion" warning. Here I'm getting this warning only on line 8 column 4. Please explain.
var console;
if (
    /non-confusing/.test(console.text)
) {
    console.log('non-confusing');
}
if (
    /non-confusing/.test(console.text) ||
    /confusing/.test(console.text)
) {
    console.log('confusing');
}
1
Douglas Crockford's profile photoЕвгений Орехов (Evgeny Orekhov)'s profile photo
4 comments
 
+Douglas Crockford Thanks. I should have read "Regular Expressions" chapter on the Instructions page before posting my question.
Add a comment...
 
{'test':'test'}
reports JSON: good.
Strings in JSON must be wrapped in double quotes.
2
Douglas Crockford's profile photoЕвгений Орехов (Evgeny Orekhov)'s profile photo
3 comments
 
+Douglas Crockford The comments example now produces two warnings on the same line and column. Is it OK?
Unexpected '(comment)'. line 1 column 4
Expected '(string)' and instead saw '(comment)'. line 1 column 4
Add a comment...
 
Cannot read property 'disrupt' of undefined line NaN column NaN
var myVar = 'test';
switch (myVar) {
case 'test':
default:
    console.log(myVar);
}
1
Shaunak Jadav's profile photoNathan Ho's profile photo
3 comments
 
+Shaunak Jadav Evgeny reported a bug in JSLint which is now fixed.
Add a comment...
 
var myObject = {
    foo: {},
    bar: (function () {
        'use strict';
        return myObject.foo;
    }())
};

JSLint should give "'myObject' is out of scope" warning on line 4.
1
Douglas Crockford's profile photoЕвгений Орехов (Evgeny Orekhov)'s profile photo
13 comments
 
+Douglas Crockford I agree. I wish JSLint could catch all stupid patterns and forced us to use the best ones.
Add a comment...

Ben Quarmby

Discussion  - 
 
JSLint correctly warns about redefining a name from the outer scope in this example:

/jslint node/

'use strict';

module.exports = function (options) {
    var subOptions = options.subOptions;

    function act() {
        var options = subOptions;

        return options;
    }

    return act();
};

But not in this example:

/jslint node/

'use strict';

module.exports = function (options) {
    var subOptions = options.subOptions;

    function act(options) {
        return options;
    }

    return act(subOptions);
};
1
Douglas Crockford's profile photoBen Quarmby's profile photo
2 comments
 
Understood, thanks.
Add a comment...

Sylvain Prat

Discussion  - 
 
function constructor() {
    if (this.initialize) {
        this.initialize.apply(this, arguments);
    }
}

This code raise a Unexpected 'arguments' warning, and I am a little annoyed! I understand it is to support the new/better ellipsis construct from ES6, but with ES5 (current), there's no way to implement this constructor function without "arguments". Could you please implement at least a "Tolerate" option?
1
Nathan Ho's profile photoSylvain Prat's profile photo
7 comments
 
I still disagree with you, my usage of JSLint before the new beta version was to eliminate bad Javascript constructs, spot developer errors and ensure consistent code formatting. I can't do that anymore with the new beta version. But ok, I guess I have to live with that or enable "this" for big legacy code. I am actually trying to use a classless style now to see how it is different from the classical inheritance model.

However, using a transpiler is a bit too much I think. JSLint is supposed to validate ES5 by default (ES6 option is disabled by default), but for the particular case of arguments, we should use ES6? I don't see the logic behind this choice, and I don't see the harm arguments do when used the way I want to use them. I would better understand if the warning was issued in ES6 mode only but that's not the case.
Add a comment...

Hannns Walfisch

Discussion  - 
 
When using an immediately invoked function wrapped in parens within a function call, JSLINT gives a warning. See below.

The example without parens should not pass, because it masks the invocation. About the second example I am not sure; JSLINT used to tolerate it, but it might be too tricky to recognize.

edition 2015-07-31

line 12 column 11
Unexpected '('.
foo.onEvent((function () {

---
var foo;

// immediately invoked function without parens gives no warning
foo.onEvent(function () {
    "use strict";
    var privee = 0;
    return function () {
        privee += 1;
    };
}());

// immediately invoked function with parens gives warning
foo.onEvent((function () {
    "use strict";
    var privee = 0;
    return function () {
        privee += 1;
    };
}()));
1
Douglas Crockford's profile photoHannns Walfisch's profile photo
2 comments
 
Ah, ok. Thanks.
Add a comment...

About this community

This group is for discussion of JSLint, including feature requests, complaints, update announcements, and testimonials.
 
I think the whitespace looks awkward here:
var array =
            [
        0,
        1
    ],
    object =
            {
        a: 0,
        b: 1
    };
1
Евгений Орехов (Evgeny Orekhov)'s profile photoDouglas Crockford's profile photo
4 comments
 
For the most part, JSLint lets you break lines where you want. If you choose to break in a way that uglifies your code, that is on you.

JSLint could forbid line breaking, but I am not ready to do that.
Add a comment...
 
var a = 1/2;
a/=2;
Shouldn't JSLint require spaces around / and /=?
2
Douglas Crockford's profile photo
 
Yes it should.
Add a comment...
 
Maybe JSLint should warn on useless empty return at the end of a function?
function f() {
    'use strict';
    console.log('test');
    return;
}
1
Ben Quarmby's profile photo
 
It's unnecessary here, but not necessarily error prone.
Add a comment...
 
JSLint should warn on duplicate case in switch statement:
var myVar = 'test';
switch (myVar) {
case 'test':
case 'test':
    console.log(myVar);
    break;
}
1
Douglas Crockford's profile photo
 
That is a good suggestion.
Add a comment...

Sylvain Prat

Discussion  - 
 
function obj() {
    "use strict";

    return {
        get value() {
            return 1;
        }
    };
}

This code raises a "Unexpected ES6 feature" warning. But AFAIK, it's available in ES5 or ES5.1. ES6 allows expressions in place of the property name. But it that case, there's no expression, so it should be allowed.
2
Евгений Орехов (Evgeny Orekhov)'s profile photoDouglas Crockford's profile photo
4 comments
 
Right.
Add a comment...
 
var object = {};
object
    .chained().
            method()
    .calls();
This looks messy, JSLint should force some consistency here.
1
Евгений Орехов (Evgeny Orekhov)'s profile photoDouglas Crockford's profile photo
8 comments
 
JSLint will warn on breaks after dots.
Add a comment...

Nathan Ho

Discussion  - 
 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n

The global RegExp object sets some properties according to the last processed regexp, such as RegExp.$1 (group #1), RegExp.input, etc. It worries me that these are practically global variables. Are they a Bad Part?
1
Nathan Ho's profile photo
4 comments
 
It looks like Douglas implemented the warning. Thanks to him!
Add a comment...

Peter

Discussion  - 
 
Unexpected character '\'.

/([a-f]+)-(\1)/g.exec("abc-abc") //["abc-abc", "abc", "abc"]
/([a-f]+)-(\1)/g.exec("abc-ab") //null

Back reference is bad?
1
Douglas Crockford's profile photo
 
I have observed that it is a mistake more often than it is intended.
Add a comment...
 
The "browser" option should not allow to use the "parent" global variable, which is a reference to the global object.
https://github.com/douglascrockford/JSLint/blob/bab010bdc3080cdfd6375c7d7574ae45684de2d0/jslint.js#L150
1
Douglas Crockford's profile photo
 
Right.
Add a comment...