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
28
votes
7 answers

What is the JSLint approved way to convert a number to a string?

I've always converted numbers to strings by adding an empty string to them: var string = 1 + ''; However, JSLint complains of this method with Expected 'String' and instead saw ''''., and it does look a little ugly. Is there a better way?
Samuel Cole
  • 2,005
  • 2
  • 14
  • 14
28
votes
4 answers

JSlint error 'Don't make functions within a loop.' leads to question about Javascript itself

I have some code that invokes anonymous functions within a loop, something like this pseudo example: for (i = 0; i < numCards; i = i + 1) { card = $('
').bind('isPopulated', function (ev) { var card = $(ev.currentTarget); …
Zhami
  • 19,033
  • 14
  • 48
  • 47
28
votes
3 answers

JsLint 'out of scope' error

function test(){ if(true){ var a = 5; } alert(a); } test(); I keep getting 'out of scope' errors in my JS code when I check with JsLint which make no sense to me.So I quickly created an example. Is there something actually…
Rajat
  • 32,970
  • 17
  • 67
  • 87
27
votes
5 answers

How to rectify "Document was used before it was defined" using Jslint

I get the following error in jsLint: 'document' was used before it was defined. Line that causes the error: document.cookie = name + "=" + value + expires + "; path=/"; I get why this happens, but I would like my code to be compliant. How do I…
starjava
  • 443
  • 2
  • 8
  • 14
26
votes
7 answers

JSLint with multiple files

JSLint works fine for just one JavaScript file. Recently, I've started breaking my program into several pieces. I don't want to be stringing the pieces each time I use JSLint to check my code. What is the standard solution to deal with multiples…
Randomblue
  • 112,777
  • 145
  • 353
  • 547
25
votes
1 answer

Expressions in JavaScript Ternary Operator and JSLint

I recently received a comment on one of my blog posts about JSLint asking why JSLint threw an error with the following: s === "test" ? MyFunc() : MyFunc2(); The error generated was: "Expected an assignment or function call and instead saw an…
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
25
votes
1 answer

How can I change jslint(VS 2010 extension) to ignore files?

I have js lint installed in Vs 2010 as a extension through the extension manager. It finds lots of errors but they are all from external plugins or from the jquery library. I am not going to go and fix stuff in an external plugin or jquery file. So…
chobo2
  • 83,322
  • 195
  • 530
  • 832
25
votes
2 answers

JavaScript: JSLint throws "Read Only

My code: note: the Slider Object is declared but omitted in the snippet below for better readability "use strict"; /*global arrayContainer, SliderInstance, DomObjects */ arrayContainer = new Slider.constructArray(); SliderInstance =…
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
24
votes
3 answers

jsLint error: “somefunction() was used before it was defined”

Why does JSLint complain if something uses a function that hasn't been defined already? The point is that the function is defined -- and if that something calls that function, that function exists and things will work. Take a look at the code…
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
23
votes
1 answer

How do I change Eclipse to use spaces instead of tabs in Javascript editor?

I use the Eclipse JavaScript plugin, I have my text editor settings to "insert spaces as tabs" this works fine until I select a block of code and tab it or shift tab it, run JSLint and AARGghh! "Mixed spaces and tabs." is there something I am…
Damen TheSifter
  • 901
  • 1
  • 6
  • 17
23
votes
17 answers

Is JSLint available for offline use?

I'd like to use JSLint, but I am wary of tools that have access to my unfiltered source code. Is there an offline version or is there another similar tool that does "lint error checking" for JavaScript offline? Edit: One with a GUI and that shows…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
23
votes
4 answers

Javascript/jsLint: What to replace jQuery(this) with when using "use strict";

When I validate the following code with jslint I get the following errors. function displayMegaDropDown() { "use strict"; var liMegaPosition, divMegaOffset; liMegaPosition = jQuery(this).position(); divMegaOffset = { top: liMegaPosition.top +…
Sarge
  • 2,367
  • 2
  • 23
  • 36
23
votes
2 answers

jslint --edition=latest Unexpected ES6 feature. const

I'm trying to use node-jslint https://github.com/reid/node-jslint in order to keep my code clean I've got a const in my nodejs script, but jslint says it isn't valid ES6 code Unexpected ES6 feature. const pdPersonsFilterId = process.argv[2]; //…
Nikage
  • 578
  • 2
  • 7
  • 18
23
votes
2 answers

JSLint mixed spaces and tabs error

I have run the following through JSLint: $(document).ready(function() { /* Add paragraph on page load */ // Get all header elements var header = document.getElementsByTagName('h1'), parent, newP, …
RyanP13
  • 7,413
  • 27
  • 96
  • 166
23
votes
3 answers

Method expression is not of Function type

I have the following JavaScript file: /*global $ */ function foo() { 'use strict'; var $tr = $('table tr'), $td = $tr.children('td'); $td.html('Hello World'); } In PHPStorm, children gets underlined with a weak warning.…
elixenide
  • 44,308
  • 16
  • 74
  • 100