Questions tagged [jslint]

JSLint is a "code quality" tool for JavaScript developed by Douglas Crockford, a well-known developer also responsible for JSON, JSMin, ADSafe and parts of YUI. JSLint is parallel to C's lint.

JSLint is a static analysis “code quality” tool for JavaScript developed by Douglas Crockford, a well-known developer also responsible for JSON, JSMin, ADSafe and parts of YUI.

The term “linting” originates from fabric lint-rollers that help remove fluff from clothing. In the same way, a code “linter” helps the developer remove fluff from their code.

The first linting tool was developed for the C programming language when early compilers were not sophisticated enough to identify common programming errors. As the language and compilers matured, so the C linter became redundant and obsolete.

As much of the JavaScript written will not have been near a compiler, the requirement for an equivalent linting tool emerged. This is where JSLint comes in.

A similar tool, exists. It was forked from JSLint.

In the words of its creator:

Warning!

JSLint will hurt your feelings.

Resources

Related Tags

1004 questions
63
votes
6 answers

How to fix jslint error 'Don't make functions within a loop.'?

I am working on making all of our JS code pass through jslint, sometimes with a lot of tweaking with the options to get legacy code pass for now on with the intention to fix it properly later. There is one thing that jslint complains about that I do…
Ernelli
  • 3,960
  • 3
  • 28
  • 34
63
votes
6 answers

Is it bad practice to use the same variable name in multiple for-loops?

I was just linting some JavaScript code using JSHint. In the code I have two for-loops both used like this: for (var i = 0; i < somevalue; i++) { ... } So both for-loops use the var i for iteration. Now JSHint shows me an error for the second…
TimG
  • 985
  • 3
  • 14
  • 24
62
votes
3 answers

(...()) vs. (...)() in javascript closures

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,…
Camilo Martin
  • 37,236
  • 20
  • 111
  • 154
60
votes
4 answers

Why were the new JSLint errors "use spaces, not tabs" and "unsafe character" introduced?

I have been validating my JavaScript using JSLint for about 2 years now and once in a while there are rules that change. In general when JSLint introduces a new rule, there is a checkbox to ignore this rule when parsing, or if you choose to not…
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
59
votes
3 answers

Why does JSLint complain about "Unexpected 'else' after 'return'"?

JSLint complains that the following (useless example) code is invalid: (function (x) { "use strict"; if (x === 1) { return 1; } else if (x === 2) { return -1; } return 0; }(1)); Error: Problem at line 4…
Hal
  • 884
  • 1
  • 7
  • 12
59
votes
5 answers

Is there a working JSLint Eclipse plug-in?

Can anyone point to a functioning JSLint plug-in for Eclipse?
Nikita
  • 6,019
  • 8
  • 45
  • 54
57
votes
3 answers

JSLint reports unexpected use of '&' and '|' -- I'd like to clean this

I'm trying to get my Javascript code 100% JSLint clean. I've got some JS code that I've lifted from elsewhere to create a UUID. That code has the following line: s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1); This line incites JSLint to generate…
Zhami
  • 19,033
  • 14
  • 48
  • 47
55
votes
1 answer

How to fix "foo is not defined" error reported by JSlint?

Possible Duplicate: JSLint: was used before it was defined I run JSlint and saw errors like that: 'foo' is not defined. var x = foo(); foo is a function defined in another JavaScript file foo.js. As I understand there is no "import / require"…
Michael
  • 10,185
  • 12
  • 59
  • 110
52
votes
4 answers

Dealing with duplicate declaration warning for loop variables

Consider the following code: for (var i=0; i<100; i++) { // your code here } // some other code here for (var i=0; i<500; i++) { // custom code here } Any decent lint tool (jslint, jshint or built in IDE) will tell warning - duplicate…
Ilya Tsuryev
  • 2,766
  • 6
  • 25
  • 29
51
votes
2 answers

JSlint: unexpected 'for'

I have been testing with radio buttons. Everything seems okay until i ran it through JS lint. I fixed all errors except one: Unexpected 'for' for (i = 0; i < radios.length; i += 1) { Here is my Javascript: /*global…
MrEhawk82
  • 811
  • 2
  • 13
  • 22
50
votes
6 answers

How can I check JavaScript code for syntax errors ONLY from the command line?

JavaScript programs can be checked for errors in IDEs or using online web apps but I'm looking for a way to detect syntax errors alone. I've tried JSLint and JSHint and looked at their options but I haven't been able to find a combination that would…
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
50
votes
7 answers

Empty functions in Javascript

If I have something like this: var blah = function() { }; and then later in code blah is being used, what is the JSLint hint that says remove the empty block?
user1899082
50
votes
3 answers

How to get "should.be.false" syntax pass jslint?

I am writing JS UT for my NodeJS code. I am using Chai as the assertion library, and I prefer the should syntax. I also use jslint to check the JS file syntax, even the JS files for UT. Now I have a problem with jslint and Chai. In Chai, you can…
David S.
  • 10,578
  • 12
  • 62
  • 104
47
votes
6 answers

Prevent JSHint warning that 'functionName is defined but never used'

I have just started using JSHint (through the Sublime-Linter package for Sublime Text 2). I would like to suppress its warnings regarding functions that are used before they are defined, as I see no problem with using function definitions like this.…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
46
votes
5 answers

Adobe Brackets disable jslint but allow jshint

My basic question: In the Adobe Brackets editor how do I use jshint while turning off or disabling jslint? My tl;dr: When linting javascript in the Adobe Brackets editor I find that I get results for both jslint and jshint. While I have jshint…
rg88
  • 20,742
  • 18
  • 76
  • 110
1 2
3
66 67