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
12
votes
1 answer

Expected ';' and instead saw ','. - JSLint multivar setting

As of about 14 January 2016, JSLint has started complaining about var or let declarations that have more than one variable per declaration, and has created a new directive, multivar that ignores this new "problem". This is a pretty significant…
ruffin
  • 16,507
  • 9
  • 88
  • 138
12
votes
6 answers

'Variable' was used before it was defined

I am checking if a variable is defined or not, and if it is not defined explicitly I am going to define it by doing: if ( typeof(aVariable) == 'undefined' ) { var aVariable = value; } Because the variable is not defined JSLint warns that it is…
nimcap
  • 10,062
  • 15
  • 61
  • 69
12
votes
2 answers

Can the label "javascript:" cause any problems?

Both JSLint and JSHint issue warnings when they encounter a labelled statement whose identifier matches the following regular expression: /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i For example, the following snippet…
James Allardice
  • 164,175
  • 21
  • 332
  • 312
12
votes
4 answers

Can you give me an example of "Bad line breaking before '?'"?

I've got this error message, that I'm not a fan of. Bad line breaking before '?'. I feel like var s = (a === b) ? 'one' : 'two'; looks better. Crockford says: Semicolon insertion can mask copy/paste errors. If you always break…
rythos42
  • 1,217
  • 2
  • 11
  • 27
12
votes
3 answers

Function was used before it was defined - JSLint

JSLint does not like this code saying "'b' was used before it was defined" var a = function () { b(); }, b = function () { alert("Hello, world!"); }; a(); but perfectly happy with this var a, b; a = function () { …
Evgeny
  • 6,261
  • 8
  • 35
  • 43
11
votes
4 answers

Disable "use the function form of use strict" but keep the "Missing 'use strict' statement" warning

I am using jslint to validate my code. I have "use strict" on all my pages. How can I disable the message "use the function form of 'use strict'" but keep the "Missing 'use strict' statement" warning, so I won't forget to put it on new files? Thanks
Randall Flagg
  • 4,834
  • 9
  • 33
  • 45
11
votes
3 answers

HTML5 Placeholder feature detection woes

I need to test for placeholder support. The following works great in all modern browsers, as well as IE7, IE8, IE9: $.support.placeholder = (function () { var i = document.createElement("input"); return "placeholder" in i; }()); It works,…
karim79
  • 339,989
  • 67
  • 413
  • 406
11
votes
6 answers

JSLint, else and Expected exactly one space between '}' and 'else' error

Why JSLint report in code: function cos(a) { var b = 0; if (a) { b = 1; } else { b = 2; } return b; } error: Problem at line 6 character 5: Expected exactly one space between '}' and 'else'. This error can…
Grzegorz Gierlik
  • 11,112
  • 4
  • 47
  • 55
11
votes
5 answers

JSLint - problems declaring variables

The following code passes JSLint: var sGreeting = 'hello world'; switch (sGreeting) { case 'Hello world!': var a = 'some a value'; break; case 'Kamusta mundo!': var b = 'some b value'; break; case 'Salut le Monde!': var c =…
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
11
votes
2 answers

Unexpected dangling '_' in '_gaq'

I'm trying to validate my Google Analytics code using JSLint but I get a lot of error messages: The code: /*global document */ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-24389816-1']); _gaq.push(['_trackPageview']); (function () { var…
thom
  • 113
  • 1
  • 1
  • 4
11
votes
3 answers

Can I prevent passing wrong number of parameters to methods with JS Lint, JS Hint, or some other tool?

I'm new to javascript programming (and scripting languages in general), but I've been using JS Lint to help me when I make syntax errors or accidentally declare a global variable. However, there is a scenario that JS Lint does not cover, which I…
tandersen
  • 365
  • 2
  • 10
11
votes
4 answers

How can I run jslint as a javascript compile tool in emacs for Windows?

I'm using GNU Emacs on Win32. I want to be able to run jslint as a compilation on .js files, and then step through the errors that jslint reports. I have jslint, the WScript version.
Cheeso
  • 189,189
  • 101
  • 473
  • 713
11
votes
4 answers

"Use the array literal notation []" for var os_map = {}

I don't understand why I get the error message when I run JSLint with a JavaScript file. I get the message var os_map = {}; Problem at line 28 character 36: Use the array literal notation []. if I run this code in JSLint. The options for the JSLint…
TK.
  • 27,073
  • 20
  • 64
  • 72
10
votes
3 answers

What's the JSLint approved way of creating a long string?

As a preface, yes I'm aware that JSLint is more of a set of guidelines than rules. While using JSLint to clean up some code that I inherited, there are a number of places where some URLs are used in strings. They're necessary for the script, but…
zzzzBov
  • 174,988
  • 54
  • 320
  • 367
10
votes
1 answer

JSLint doesn’t expect my tildes

JSLint insists that my use of the somewhat exotic tilde operator in the below example is unexpected. What I’m wondering is whether this is a limitation of JSLint? or strict mode? or what else am I missing? (function () { 'use strict'; if…
Daniel
  • 4,525
  • 3
  • 38
  • 52