The JavaScript Code Quality Tool
See all
Members (720)
Douglas Crockford's profile photo
Madara Uchiha's profile photo
Maulik Gangani's profile photo
Carolyn Stephany Ulfe Ureña's profile photo
Ahmed Abdalla's profile photo
Sri Mathy's profile photo
DulowKaotic DulowKaoticCHECKTHIS's profile photo
William Malone's profile photo
Paul Crowder's profile photo
Denis Bešić's profile photo
Oliver Guether's profile photo
Bnaya Peretz's profile photo
Paul Wilkins's profile photo
Christopher Karl Johansen (Xojo)'s profile photo
Allen Chen's profile photo
Juliano Lazzarotto's profile photo
Karol L's profile photo
Shravan Kumar Kasagoni's profile photo
psp i's profile photo
N Shathish's profile photo
Arild Haugstad's profile photo
Josef Jelinek's profile photo
Mariane Machado's profile photo
Mick GRZ's profile photo

Stream

Tom Brodhead

Discussion  - 
 
I believe the documentation on the white space requirements for ternary operators could be improved with an example. The current description:

"The ternary operator can be visually confusing, so ? question mark and : colon always begin a line and increase the indentation by 4 spaces."

...was ambiguous to me. It could be illustrated clearly with:

var x = Math.PI > 4
? "Yep"
: "Nope";

...or similar, which I only obtained by trial and error. (I placed 4 white spaces before the 2nd and 3rd lines above, but this editor will likely strip them out when I submit this post.)
1
Douglas Crockford's profile photo
 
Thanks.
Add a comment...

raal Bvv

Discussion  - 
 
Is there any plan to add another environment to JSLint ? we already have browser, which defines XMLHttpRequest, document and more as globals, we already have node that defines require Buffer etc. Now it would be cool to have the worker mode , for web workers , service workers and shared workers, . Also worker don't have DOM access, and are isolated, so there is no need to wrap it in an IIFE, , right now workers passed to JSLint get Unexpected 'use strict'. error, which is kinda wrong see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
A worker is an object created using a constructor (e.g. Worker()) that runs a named JavaScript file — this file contains the code that will run in the worker thread; workers run in another global context that is different from the current window. Thus, using the window shortcut to get the current global scope (instead of self) within a Worker will return an error.
1
Douglas Crockford's profile photo
 
Are you proposing something?
Add a comment...

Doug Kunzman

Discussion  - 
 
I have a question about arrow functions. Our code looks like this...
router.get('/hello', (req, res) => {
res.json({
message: 'Hello Test'
});
});
and JSLint is returning the following warning "Expected 'function' and instead saw '=>'." Does JSLint ever accept arrow functions when es6 is enabled? If not why are arrow functions universally bad? I'm running JSLint from github inside a tomcat container that was pulled yesterday.
1
Douglas Crockford's profile photoLee Chase's profile photo
2 comments
 
Arrow functions have a problem with { }, mainly is it a multiline function or an object.

As it happens your function returns nothing as multiline arrow functions need a return. You could write as

router.get('/hello', (req, res) => res.json({message: 'Hello Test'}));

Linter may still object.
Add a comment...

Doug Kunzman

Discussion  - 
 
JSLint is giving me the error Unexpected 'const' for the line const t = 5. I don't understand why? My .jslintrc is as follows:
{
"node": true,
"indent" : 2,
"esnext": true,
"quotmark": "double",
"esversion": 6
}
any help would be appreciated. I'm using version 0.10.1 on a mac. If the problem is my version is old is there an easy way to get the latest version on a mac?
1
Douglas Crockford's profile photoDoug Kunzman's profile photo
2 comments
 
Yes, I'm using some old code. I just tried it with your tool and its great! Love your book bye the way.
Doug
Add a comment...

raal Bvv

Discussion  - 
 
Escaping a backtick in a template literal twice creates a wrong warning, const a = `\` blababa \``; 
1
Douglas Crockford's profile photoraal Bvv's profile photo
2 comments
 
I dont see it more complex than escaping quotes with \" in normal strings
Add a comment...

Douglas Crockford
owner

Discussion  - 
 
Should JSLint warn on get and set?

We are transitioning way from use of mutation and side effects. Getters and setters, by enabling side effects on simple assignment, seem to be going in the wrong direction.
38 votes  -  votes visible to Public
Warn on get and set
79%
No warning
21%
1
Felix E. Klee's profile photoJames Long's profile photo
20 comments
 
Just so I understand the issue, +Douglas Crockford  are you saying that you feel JSLint should warn on a case with getters and setters, similar to this:

var o1 = {};
Object.defineProperty(o1, "length", {

    set: function (value) {

        o1.length = value;

        if (!o1.lengths) {
            o1.lengths = [];
        }

        o1.lengths.push(value);

    }

});

o1.length = 1;
o1.length = 2;
o1.length = 3;

and JSLint would prefer something more like this:

var o2 = {

    setLength: function (value) {

        o2.length = value;

        if (!o2.lengths) {
            o2.lengths = [];
        }

        o2.lengths.push(value);

    }
    
};

o2.setLength(1);
o2.setLength(2);
o2.setLength(3);

If so, I'm more-or-less in favour. I've never used getters and setters before and I feel that a function call like setLength() makes it far more obvious that side effects could occur.

Out of interest, how would you/JSLint feel about using Proxy to create magic getter and setter methods similar to the Varien_Object in Magento?
Add a comment...

Brian Kieffer

Discussion  - 
 
Why does the following code pass JSLint?

(function () {
"use strict";

var foo = true;

if (foo) {
var bar = 0;
alert(bar);
}
}());

Shouldn't this be:

(function () {
"use strict";

var foo = true;
var bar;

if (foo) {
bar = 0;
alert(bar);
}
}());
1
Douglas Crockford's profile photoBrian Kieffer's profile photo
7 comments
 
+Douglas Crockford I see. Thanks for the explanation!
Add a comment...

Mathias Nater

Discussion  - 
 
function foo() {
"use strict";
bar();
}

function bar() {
"use strict";
return undefined;
}

gives: 'bar' is out of scope
That's OK and I understand why.

function foo() {
"use strict";
bar();
}

function bar() {
"use strict";
foo();
}

gives no warning.
I don't understand why.

function foo() {
"use strict";
bar();
}

function bar() {
"use strict";
function inner() {
foo();
}
inner();
}

again: 'bar' is out of scope.

What's the rules here?
1
Add a comment...
 
/*jslint es6, browser */
function f(...args) {
"use strict";
console.log(args);
}

V8 throws "SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list", but JSLint disallows the file form of strict pragma in browser mode.

What should I do?
1
Евгений Орехов (Evgeny Orekhov)'s profile photo
12 comments
 
+Douglas Crockford oh, JSLint gives the "Unexpected 'use strict'" warning for the above IIFE, but it should not!
Add a comment...
 
The necessity of 'use strict' in modules is dependent on the position of import or export statements:

function id(a) {
return a;
}

export default id;

Expected ' "use strict"; ' before 'return'.

vs

var b = 1;

export default b;

function id(a) {
return a;
}

Unused 'id'.
1
mizuki nakeshu's profile photo
 
maybe it is because id can never be called this way?
Add a comment...

About this community

This group is for discussion of JSLint, including feature requests, complaints, update announcements, and testimonials.

Tom Brodhead

Discussion  - 
 
I'm trying to eliminate 'this' in some JQuery code. The code makes use of the $(selector).each() function, documented here:

https://api.jquery.com/each/

Although the documentation provides an example of a way to use an equivalent function that does not use 'this', the first example they provide requires 'this' and is a thorn to JSLint:

$("li").each(function(index) {
console.log(index + ": " + $(this).text());
});

My code is a bit more complex, but if there's a way to avoid using 'this' while using .each() (instead of abandoning it for a different operator), it would be preferable. The relevant lines from a sample code block I'm trying to edit are:

$("#edit_keyword_form :checkbox").not("#new_keyword :checkbox").each(function () {
$(this).on("click", function () {
if ($(this).is(":checked")) {
var li = $(this).parent("li");
// more code follows
}
});
});
jQuery: The Write Less, Do More, JavaScript Library
1
Add a comment...

Tom Brodhead

Discussion  - 
 
This code:

var x = new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "g");

Produces this JSLint "unable to finish" response:

Expected ']' and instead saw '-'.

...at character position 36

How do I alter the regex (which is valid and apparently well-formed) to allow JSLint to finish?
1
Douglas Crockford's profile photoTom Brodhead's profile photo
14 comments
 
Many thanks!
Add a comment...

Tom Brodhead

Discussion  - 
 
JSLint fails to recognize functions that begin with a capital letter. For example:

"use strict";
var console;
function X(text) {
console.log(text);
}
X("Hello");

...throws the warning "Expected 'new' before 'X'" in reference to X("Hello");

On the other hand, if the function does not begin with a capital letter, it issues no such warning. Is there a convention to avoid capitalizing function names in deference to a different JavaScript type (here, presumably an object) that typically is capitalized?
1
Tom Brodhead's profile photoStéphane Trebel's profile photo
3 comments
 
It's mentionned in http://www.jslint.com/help.html ("Constructors and new" section) if you want to have a little more insight on this
Add a comment...
 

Proposal: Every function should have zero or one parameter.
Multiple arguments can be passed by wrapping them in an object.
This restriction will make programs more extensible and easier to read.
old way: draw_rect(0, 0, 50, 50)
new way: draw_rect({ x: 0, y: 0, width: 50, height: 50 })
In my opninion the old way is almost as cryptic as assembly language.
4
Fedge No's profile photoΝίκος Καλογρίδης's profile photo
5 comments
 
+Fedge No​ you are always in development mode in software 😃
Add a comment...
 
Should JSLint favor

const foo = function foo(...) {
...
};

over

function foo(...) {
...
}

when es6 is enabled? The former will throw a TypeError if foo is reassigned. JSLint already warns when a function name is reassigned and if is used before is declared.
1
Nicola Squartini's profile photo
3 comments
 
I mentioned that JSLint already warns when a function name is reassigned; the "const" form would also cover the case when the function is exported and reassigned in the importer module.
Add a comment...

Chris Rowett

Discussion  - 
 
This works:
var a = "a", b = a.charCodeAt(0);

But this reports a problem:
var c = "a".charCodeAt(0);

Unexpected '.'.

Why?
1
Brian Kieffer's profile photoNicola Fankhauser's profile photo
3 comments
 
See the discussion in this thread where interestingly this behavior was described as intentional: https://plus.google.com/116155444999910002488/posts/EdhyU8tYn1Y

Add a comment...

Harry Whitfield

Discussion  - 
 
On JSLint 2016-05-25, the following example code was good. On JSLint 2016-06-03 it produces Unexpected 'use strict'. errors. Is this a bug or a change of policy. Please explain.

/*jslint browser, this */
/*global window */

function openNotes() {
"use strict";
window.open("Help.html");
}
function mouseEnter() {
"use strict";
this.style.color = "#FF0000";
}
1
Douglas Crockford's profile photoHarry Whitfield's profile photo
4 comments
 
+Douglas Crockford All well - thanks.
Add a comment...

Felix E. Klee

Discussion  - 
 
JSLint 2016-06-03 complains about redefinition of “x”, rightly so? (talking about readability, this forum is a nightmare – code formatting is lost, would prefer a simple mailing list)

/*jslint node: true, es6: true */

'use strict';

var x = null;

console.log(x);

module.exports = {
set x(newX) {
x = newX;
}
};
1
Felix E. Klee's profile photoDouglas Crockford's profile photo
6 comments
 
G/S was one of the only features from the ill-fated ES4 project to make it into ES5. The motivation was to allow construction of DOM-like interfaces, ignoring the fact that the DOM was one of the worst interfaces ever imagined.

G/S breaks what used to be an important invariant: reading or writing a property is a completely local action that is free of side effects. That makes programs easier to reason about.

    Side effects are often confusing to program
    readers because they are unexpected: the
    familiar expressions of conventional
    arithmetic and algebra do not have side
    effects.

    [RC Tennent, Principles of Programming Languages]
Add a comment...
 
I would love to check for variables being initialized in the following way:

    function check(arg) {
        return arg !== undefined;
    }

    var alpha = 0;
    var beta = 1;
    var gamma;

    if ([alpha, beta, gamma].every(check)) {
        // do
    }

Yet JSLint does not approve with putting an array method right next to its declaration.

While I get that this could prevent madness in some cases – for things like every() (and .forEach? or .reduce?) I'd argue there are valid uses.

Should I start adding a line declaring the array; or could you imagine allowing direct use of array methods?
1
Jonas M. Schlatter's profile photoWilliam Chapman's profile photo
5 comments
 
Array literals in JavaScript is a Good Part. By proscribing method calls on array literals, the goodness is diminished. (Ditto for object literals in JavaScript.)
Add a comment...
 
JSLint keeps telling me "Unexpected 'instanceof'" when it checks the line

if (activity instanceof HTMLDocument || activity instanceof XMLDocument)

in which I just want to assure if a paremeter might be a document of on of both types. Just did not find a hint to why that would be an error?
1
Douglas Crockford's profile photoraal Bvv's profile photo
2 comments
 
1 alternative way to check if it is an HTMLDocument would be to check if the activity has HTML specific fields. You can use hasOwnProperty to do that.
Add a comment...