JSLint Messages – Coding Convention and Style Guide
Why Bother? JSLint contains a number of messages pertaining to the style, appearance and formatting of JavaScript code. This includes stipulations about bracing positions, indentation and spacing. As a...
View ArticleJSLint Messages – Do not wrap function literals in parens unless they are to...
In JavaScript we can assign a function expression to a variable, like so: var foo = function() { return 1; }; //assign function expression to 'foo' This is perfectly valid, and often useful. It is also...
View ArticleJSLint Messages – Wrap an immediate function invocation in parentheses…
This is the longest error message that JSLint boasts. In full it reads: “Wrap an immediate function invocation in parentheses to assist the reader in understanding that the expression is the result of...
View ArticleJSLint Messages – Missing name in function statement
JSLint reports this error when a function name has been omitted from a functions statement. For example: function(a) { alert(a); } It is possible that the original intention was more like the...
View ArticleJSLint Messages – Function statements should not be placed in blocks
This message was acutally too long for the subject title. In full, it reads: “Function statements should not be placed in blocks. Use a function expression or move the statement to the top of the outer...
View ArticleJSLint Messages – Move the invocation into the parens that contain the function
With this message we move deep into the heart of JavaScript closures. Without wanting to engage into a discussion about what they or their relative merits are, we can examine how this message might...
View ArticleJSLint Messages – Use the array literal notation []
JSLint has very specific constraints about how you use new. This message is displayed when JSLint encounters an object that has been constructed using new Array() instead of simply = []. In JavaScript...
View ArticleJSLint Messages –‘{a}’ is a function.
JavaScript functions can be written as a declaration or as expression, as in the following examples: function a(){} //function declaration var a = function(){}; //function expression The first line...
View ArticleJSLint Messages – Bad Assignment
JSLint prompts you with this message when it encounters what it perceives to be a dangerous, or “bad” assignment. For example: document.getElementById("text"+x) = function(){}; In the above code, we...
View ArticleJSLint Messages – Don’t make functions within a loop.
In JavaScript we can declare a function anonymously, and using a concept known as late-binding we can attach the event to an HTML object: document.getElementById("control").onclick =...
View ArticleJSLint Messages – Expected to see a statement and instead saw a block.
A programming convention that is frequently carried into JavaScript from other languages (often by C++ and C developers) is the scoping of functionality within isolated blocks of code (i.e. between...
View ArticleJSLint Messages – A leading decimal point can be confused with a dot ‘.{a}’
With this message, JSLint is warning you of a potentially hazardous use of the decimal point. The following code will yield this error: alert(.2); Here. JSLint is picking out conventions that may be...
View ArticleJSLint Messages – A trailing decimal point can be confused with a dot ‘{a}’.
I kept stumbling across this one when investigating the message A dot following a number can be confused with a decimal point. This particular message proved easier to produce than the aforementioned...
View ArticleJSLint Messages – A dot following a number can be confused with a decimal point.
This is a strange one, and took some tracking down. Most attempts to bring about this message merely yielded another similar message: A trailing decimal point can be confused with a dot ‘{a}’....
View ArticleJSLint Messages – Expected a conditional expression and instead saw an...
It could be argued that this is one of the family of messages under Expected ‘{a}’ and instead saw ‘{b}’. One of my university professor referred to as ‘error 1′, because it was the single most common...
View Article