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
96
votes
9 answers

JSLint Expected '===' and instead saw '=='

Recently I was running some of my code through JSLint when I came up with this error. The thing I think is funny about this error though is that it automatically assumes that all == should be ===. Does that really make any sense? I could see a lot…
Metropolis
  • 6,542
  • 19
  • 56
  • 86
95
votes
2 answers

JSLint: was used before it was defined

Hi I have the 3 javascript files. jquery.js utility.js file1.js In file1.js I have jQuery.noConflict() jQuery(document).ready(function($) { // .... }); I get an error 'jQuery' was used before it was defined. and 'document' was used before it…
Chun ping Wang
  • 3,879
  • 12
  • 42
  • 53
94
votes
6 answers

Why do TSLint and JSLint report empty blocks?

From time to time, I get TSLint errors "block is empty". This happens e.g. when I pass a no-op callback to a function: doSomething(() => {}); From what I read, JSLint apparently does the same, but I didn't verify that. I find these usages…
theDmi
  • 17,546
  • 6
  • 71
  • 138
86
votes
3 answers

How to tell JSLint / JSHint what global variables are already defined

In my project we have some global variables that work as containers: MyProject.MyFreature.someFunction = function() { ... } So then I use that script across the site and JSLint / JSHint complains about that: 'MyProject' is not defined I know that…
Emiliano Zilocchi
  • 1,075
  • 1
  • 8
  • 12
80
votes
7 answers

Function declaration in CoffeeScript

I notice that in CoffeeScript, if I define a function using: a = (c) -> c=1 I can only get the function expression: var a; a = function(c) { return c = 1; }; But, personally I often use function declaration,for example: function a(c) { …
Grace Huang
  • 5,355
  • 5
  • 30
  • 52
79
votes
8 answers

JSLint message: Unused variables

what can I do if JSLint complains about "i" being an unused variable in such a scenario: var items = ""; $.each(data, function (i, item) { items += "
TheFitGeekGirl
  • 1,233
  • 1
  • 12
  • 17
79
votes
7 answers

JSLint error: Move all 'var' declarations to the top of the function

JSLint site updated, and I cannot check JS scripts anymore. For me, this warning is not critical, and I don't want to go through thousands of lines to fix this, I want to find more critical problems. Does anybody know how to turn off this error, or…
Oleg Yaroshevych
  • 1,285
  • 1
  • 11
  • 9
79
votes
11 answers

What is the correct way to check if a global variable exists?

JSLint is not passing this as a valid code: /* global someVar: false */ if (typeof someVar === "undefined") { var someVar = "hi!"; } What is the correct way?
Ebrahim Byagowi
  • 10,338
  • 4
  • 70
  • 81
76
votes
8 answers

JSLint: Using a function before it's defined error

I'm using JSLint to verify most of my external Javascript files, but the largest amount of errors I'm getting is from functions being used before they're defined. Is this really an issue I should worry about? It seems Firefox, IE7 and Chrome don't…
Chris S
  • 64,770
  • 52
  • 221
  • 239
76
votes
1 answer

Don't make functions within a loop

What would be the correct way to solve the jslint error in this case? I'm adding a getter function to an object which uses this. I don't know how to do this without creating the function inside the loop. for (var i = 0; i
Thijs Koerselman
  • 21,680
  • 22
  • 74
  • 108
75
votes
5 answers

JSLint's issue with 'window' as a global variable

So I'm using JSLint to try and detect errors. I turn some options off I don't like, but I don't see any way to enable being able to use the window global variable. Well, there is the Yahoo Widget option, but that's overkill. What's the deal with…
Bjorn
  • 69,215
  • 39
  • 136
  • 164
74
votes
1 answer

JSLint error: "Move the invocation into the parens that contain the function"

What does JSLint mean by this error? And how should it be rewritten? Error: Problem at line 78 character 3: Move the invocation into the parens that contain the function: })(jQuery);
Sam
  • 15,254
  • 25
  • 90
  • 145
73
votes
4 answers

JSLint reports "Unexpected dangling" character in an underscore prefixed variable name

I know that some people consider the presence of a leading underscore to imply that a variable is "private," that such privacy is a fiction, and assume this is why JSLint reports such names with an error message. I use Google Analytics on a Web site…
Zhami
  • 19,033
  • 14
  • 48
  • 47
73
votes
4 answers

What is array literal notation in javascript and when should you use it?

JSLint is giving me this error: Problem at line 11 character 33: Use the array literal notation []. var myArray = new Array(); What is array literal notation and why does it want me to use it instead? It shows here that new Array(); should work…
Matt
  • 5,547
  • 23
  • 82
  • 121
63
votes
7 answers

What is the reason behind JSLint saying there are "too many var statements"

JSLint (with the onevar flag turned on) is flagging some javascript code that I have with the following: Problem at line 5 character 15: Too many var statements. I am happy to fix these errors, but I'd like to know, am I doing it for performance or…
slolife
  • 19,520
  • 20
  • 78
  • 121
1
2
3
66 67