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
17
votes
3 answers

Pre Commit Hook for JSLint in Mercurial and Git

I want to run JSLint before a commit into either a Mercurial or Git repo is done. I want this as an automatic step that is set up instead of relying on the developer (mainly me) remembering to run JSLint before-hand. I normally run JSLint while…
jrburke
  • 6,776
  • 1
  • 32
  • 23
16
votes
2 answers

How to fix JSLint "missing new" error

Code below passed through JSLint causes an error: Problem at line 8 character 9: Missing 'new'. ResizeGrid(); How to fix? "use strict"; var ResizeGrid; function t() { var x; if (x) { ResizeGrid(); } }
Andrus
  • 26,339
  • 60
  • 204
  • 378
16
votes
2 answers

How come JQuery doesn't pass JSLint?

Possible Duplicate: What good is JSLint if jQuery fails the validation http://code.jquery.com/jquery-1.4.4.js Go to there and paste it in www.jslint.com Isn't Jquery supposed to be valid....
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
16
votes
4 answers

JavaScript: Error - "Expected an assignment or function call and instead saw an expression"?

I am using JSLint to ensure my JavaScript is "strict" and I'm getting the following error: Expected an assignment or function call and instead saw an expression On the following code: (my_var > 0 ) ? $("#abc").html(my_array.join('')) :…
HeatherK
  • 2,293
  • 4
  • 20
  • 12
16
votes
7 answers

Does it make any sense to use JSLint and follow it?

Lately I've been writing some JS code using jQuery and JavaScript as it is and I thought I will give JSLint a try. Let me say that the code contains various functions and jQuery usages and it works fine (without any errors ) in IE8 and latest…
mare
  • 13,033
  • 24
  • 102
  • 191
16
votes
2 answers

Should I worry about "window is not defined" JSLint strict mode error?

This won't pass JSLint in strict mode: "use strict"; (function (w) { w.alert(w); }(window)); The error--from jslint.com--looks like this: Problem at line 4 character 3: 'window' is not defined. }(window)); Implied global: window 4 Do I need to…
Kent Brewster
  • 2,480
  • 2
  • 22
  • 27
16
votes
2 answers

JSLint error "A leading decimal point can be confused with a dot"

I'm using jslint.com to validate some functions and came across the error: "A leading decimal point can be confused with a dot" The line which triggered the error is as follows: if ( myvar = .95 ){ How do I correct it?
user_78361084
  • 3,538
  • 22
  • 85
  • 147
15
votes
4 answers

JSLint to ignore undefined variables

I have chopped my js program into many pieces for development. Now when I run one piece through JSLint, I get a lot of errors of the type: Problem at line 48 character 42: 'XXXXXXX' was used before it was defined. I've looked for an option…
Randomblue
  • 112,777
  • 145
  • 353
  • 547
15
votes
5 answers

JSLint (CLI): options?

I'm running JSLint's Rhino version from the Ubuntu command line like so: $ rhino jslint.js myScript.js While the web interface offers various options, I couldn't figure out how to invoke those via the command line. Am I overlooking anything in the…
AnC
15
votes
4 answers

Unexpected token operator «=», expected punc «,»

i am getting the following error Parse error: Unexpected token operator «=», expected punc «,» Line 159, column 26 This is my code function fitBounds(type="all", shape=null) { var bounds = new google.maps.LatLngBounds(); if ( type ==…
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
15
votes
3 answers

How to define a new global function in javascript

I have an issue trying to make a function global when it is involved in closure. In the code listed below I have an anonymous method which defines at new function on the window called, getNameField. (function () { function alertError (msg) { …
Eric
  • 6,563
  • 5
  • 42
  • 66
15
votes
4 answers

How to properly return an empty function?

I'm using a run-time assignment of functions to account for browser differences. However for un-supported browsers, I want to return an empty function so that a JavaScript error is not thrown. But, jslint complains about empty functions. What is…
user1637281
15
votes
1 answer

How to tell JSLint not to ask for { on single line if statements

Right now I have the following code: if (c > last) break; And jslint complains with jslint:crud.js:69:19:Expected '{' and instead saw 'break'. There are several ways to overcome it: if (c > last) { break; } or if (c > last) { break; } But…
opensas
  • 60,462
  • 79
  • 252
  • 386
15
votes
4 answers

Why does JSLint prefer dot notation over Square Bracket?

I've been linting some of my code and got some errors back saying it is better to use dot notation. I found out I was using square bracket notation (with clarity from this great post), however, I wanted to ask why exactly does Crockford prefer dot…
streetlight
  • 5,968
  • 13
  • 62
  • 101
15
votes
3 answers

Why does JSLint tell me to use "=== undefined" instead of "typeof ... === 'undefined'"?

I coded the following: showTitles = (typeof showTitles !== 'undefined') ? showTitles : 'Y'; showSelectGroup = (typeof showSelectGroup !== 'undefined') ? showSelectGroup : 'Y'; But JSLint is saying: Warning 3 JS Lint: Unexpected 'typeof'. Use '==='…
user1679941