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
8421
votes
31 answers

What does "use strict" do in JavaScript, and what is the reasoning behind it?

Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error: Problem at line 1 character 1: Missing "use strict" statement. Doing some searching, I realized that some people add "use strict"; into their…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
982
votes
9 answers

JSLint is suddenly reporting: Use the function form of "use strict"

I include the statement: "use strict"; at the beginning of most of my Javascript files. JSLint has never before warned about this. But now it is, saying: Use the function form of "use strict". Does anyone know what the "function form" would be?
Zhami
  • 19,033
  • 14
  • 48
  • 47
901
votes
20 answers

How to initialize an array's length in JavaScript?

Most of the tutorials that I've read on arrays in JavaScript (including w3schools and devguru) suggest that you can initialize an array with a certain length by passing an integer to the Array constructor using the var test = new Array(4);…
Michael Martin-Smucker
  • 11,927
  • 7
  • 31
  • 36
671
votes
11 answers

JSLint says "missing radix parameter"

I ran JSLint on this JavaScript code and it said: Problem at line 32 character 30: Missing radix parameter. This is the code in question: imageIndex = parseInt(id.substring(id.length - 1))-1; What is wrong here?
Mike Vierwind
  • 6,889
  • 3
  • 15
  • 9
464
votes
8 answers

Should I use JSLint or JSHint JavaScript validation?

I am currently validating my JavaScript against JSLint and making progress on, it's assisting me to write better JavaScript - in particular in working with the Jquery library. I have now come across JSHint, a fork of JSLint. So I am wondering for…
amateur
  • 43,371
  • 65
  • 192
  • 320
393
votes
17 answers

Why avoid increment ("++") and decrement ("--") operators in JavaScript?

One of the tips for jslint tool is: ++ and -- The ++ (increment) and -- (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and…
artlung
  • 33,305
  • 16
  • 69
  • 121
391
votes
19 answers

Why does JSHint throw a warning if I am using const?

This is the error I get when using const: My code looks like this: const…
Andre Schlesinger
  • 3,925
  • 2
  • 12
  • 6
279
votes
9 answers

What does the JSLint error 'body of a for in should be wrapped in an if statement' mean?

I used JSLint on a JavaScript file of mine. It threw the error: for( ind in evtListeners ) { Problem at line 41 character 9: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. What…
jrharshath
  • 25,975
  • 33
  • 97
  • 127
227
votes
12 answers

What is the difference between `new Object()` and object literal notation?

What is the difference between this constructor-based syntax for creating an object: person = new Object() ...and this literal syntax: person = { property1 : "Hello" }; It appears that both do the same thing, although JSLint prefers you use…
ectype
  • 14,865
  • 5
  • 21
  • 28
192
votes
11 answers

How to split a long regular expression into multiple lines in JavaScript?

I have a very long regular expression, which I wish to split into multiple lines in my JavaScript code to keep each line length 80 characters according to JSLint rules. It's just better for reading, I think. Here's pattern sample: var pattern =…
Nik Sumeiko
  • 8,263
  • 8
  • 50
  • 53
165
votes
9 answers

How do you use vim's quickfix feature?

I'm a pretty new Vim user and I've found that its learning curve is quite steep (at least for me). I just installed this vim script for JavaScriptLint error checking, which shows errors in vim's quickfix window once I save a buffer. However, I don't…
hora
  • 3,661
  • 5
  • 25
  • 26
147
votes
8 answers

The "unexpected ++" error in jslint

What is the best practice for that then? Jslint explains that it "adds confusion". I don't see it really... EDIT: The code, as requested: var all,l,elements,e; all = inElement.getElementsByTagName('*'); l = all.length; elements = []; for…
KdgDev
  • 14,299
  • 46
  • 120
  • 156
123
votes
4 answers

JavaScript function order: why does it matter?

Original Question: JSHint complains when my JavaScript calls a function that is defined further down the page than the call to it. However, my page is for a game, and no functions are called until the whole thing has downloaded. So why does the…
Chris Tolworthy
  • 2,066
  • 4
  • 20
  • 24
114
votes
3 answers

Immediate function invocation syntax

There is a JSLint option, one of The Good Parts in fact, that "[requires] parens around immediate invocations," meaning that the construction (function () { // ... })(); would instead need to be written as (function () { // ... }()); My…
Bobby Eickhoff
  • 2,585
  • 2
  • 23
  • 22
101
votes
4 answers

Why is JSHINT complaining that this is a strict violation?

I think this may be a duplicate of Strict Violation using this keyword and revealing module pattern I have this code: function gotoPage(s){ if(s<=this.d&&s>0){this.g=s; this.page((s-1)*this.p.size);} } function pageChange(event, sorter) { …
Cheeso
  • 189,189
  • 101
  • 473
  • 713
1
2 3
66 67