jslint

What's the best way to built a JavaScript object so that it works AND passes JSLint?

I've been trying to see if I can build my JavaScript objects as intuitively as possible while making sure it's as 'correct' as possible. I've been running a bunch of different scenarios through Crockford's JSLint.com and haven't had much luck. I seem to fix one error, then another pops up because of the change. Below is about as good as ...

Validating removeEventListener with JSLint

I understand why JSLint kicks up a warning here, but I don't know how else to write my code so it validates. Here's a boiled down sample. In the code below, I have an object that I need to attach two event listeners to: one for "complete" and the other for "error". Each points to its own event handler. When either event handler is reac...

How does JSLint's function-within-a-loop error apply when using jQuery's .each()?

I'm using a jQuery .each() call, which uses an anonymous function, from inside a for loop. JSLint comes up with the warning "Don't make functions within a loop". Here's a code snippet from a larger function - in essence it is doing a check of whether each player of the game is still "alive" (has at least one piece on the board). for( i...

JSLint mixed spaces and tabs error

Hi, 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, text; // Loop through the elements for (var i=0, m = header.length; i < m; i++...

JSLint "Unsafe character"

I was happily using Douglas Crockford's JSLint on Mac OS X and my code passes, but after I got a Ubuntu Hardy Slicehost server and uploaded my code there, the JSLint no longer passes when I try to run it on the server. It fails on my localized files that contain umlauts. I get errors like: Lint at line 1206 character 25: Unsafe charact...

jslint documentation

Hi all, All of our js files are neatly validating against jslint. That's in itself a great benefit, but now we'd like to generate some documentation, specifically, we'd like to generate a report specifying of every js file in a directory what it's global variables are and if they are readonly or not. Is there an easy way to achieve that...

JSLint : Why this warning?

Why JSLint is producing this kind of warning Problem at line xxx character yyy: Expected 'X' to have an indentation at xx instead at yyy. Why does it matter to have a different space formatting? ...

JSLint - ignore sections of code

I have a huge script that passes JSLint (including avoidance of all bad parts). Except for one stretch, which is some very convoluted obfuscated code that is embedded within the larger context. JSLint generates quite a bit of complaints for this section, and I'd like to selectively disable it for that stretch of code. I already do use se...

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 = Object.beget(Slider); DomObjects = { animationContainer: document.getElementById('animationContain...

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 of instances that you would not want to compare type, and I am worried that this could ac...

Preparing To Make Website Internet Explorer 8 Compatible

I have just taken over maintenance of a large web application which is over 10,000 lines of Javascript. At the moment it runs on Firefox 3.5+, Safari 4+ and Chrome and I have to make it work with IE8. I am a very experienced programmer but I only have a little Javascript experience - although I have been introduced to the dubious pleas...

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 Firefox. The code also validatas as XHTML 1.0 Transitional (and Strict too but I mostly want it ...

Is there a way to make JSLint happy with this regex?

When running my Javascript through JSLint, I get the following two errors from the same line of code. Problem at line 398 character 29: Insecure '.'. if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) Problem at line 398 character 41: Unescaped '^'. if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) I understand that JSLint m...

How can I escape characters inside of this regular expression?

I have this function which will validate an email address. jsLint gives an error with the regular expression complaining about some of the characters being un-escaped. Is there a way to correctly escape them? var validateEmail = function(elementValue){ var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return...

Undefined jQuery value when trying to correct JSLint complaint: "Don't make functions within a loop"

Within a jQuery ajax function data supplied to the callback function on success is defined with success: function (data) { ... but this makes JSLint unhappy ("Don't make functions within a loop"). If I follow the suggestion in http://stackoverflow.com/questions/3037598/how-to-get-around-the-jslint-error-dont-make-functions-within-a-...

Why does JSLint restrict the use of HTML event handlers?

Using the "Good Parts" defaults on JSLint, the use of HTML event handlers (such as onclick) is not allowed. What is the logic behind this? What is bad about them that should be avoided? ...

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){ alert(msg); } window.getNameField=function(fieldId){ try{ if...

How can I use JSLint for a segment of code which depends on JQuery?

I'm relatively new to Javascript, and I'd like to run the piece of code I spent the weekend playing with through JSLint so that it can point out where I was being a total idiot :) Unfortunately, I get tons of errors about missing function declarations, which are part of the JQuery javascript library and various plugins for it. Is there...

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 = $('<div>').bind('isPopulated', function (ev) { var card = $(ev.currentTarget); .... JSLint reports the error 'Don't make functions within a loop.' I like to keep my code...

How should I replace my naughty JSLint-shy function defs within loops?

I'm getting a few "Don't make functions within a loop." errors from JSLint, anyone got any tidy suggestions on how to fix this stuff up? Perhaps my naughtiness is excusable because of my YAHOO dependencies (yd. below)? I can safely say that the only time I've done the following: for( var i=0; i<FLN.revealers.length;i++ ) { var revE...