Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make JSLint tolerate a leading semi-colon?

The continuous integration software I am using runs JavaScript files through JSLint and complains if they fail (using default JSLint settings it appears).

I've always prepended a ; to the start of my jQuery plugins, so concatenating them doesn't lead to something like this...

common.js

I don't have access to this file, and can't enforce a semi colon at the end.

var abc = function() {
    alert(arguments[0]);
}

plugin.js

This is my file that is concatenated with common.js. It is appended straight to the end of common.js.

(function($) {
    $.fn.somePlugin = function() {}
})(jQuery);

jsFiddle of the problem this can cause.

jsFiddle of the solution (leading semi-colon of my plugin).

However, JSLint complains with...

Error:

Problem at line 1 character 1: Unexpected space between '(begin)' and ';'.

;(function($) {

Problem at line 1 character 1: Expected ';' at column 5, not column 1.

;(function($) {

Problem at line 1 character 2: Missing space between ';' and '('.

...

I tried using a bang operator (!) instead, and a few other alternatives, but JSLint still complained.

What can I do to get this safety net and pass JSLint?

like image 371
alex Avatar asked Aug 17 '11 01:08

alex


1 Answers

Patch JSLint to not mind. Everyone will benefit.

like image 161
Ned Batchelder Avatar answered Oct 20 '22 00:10

Ned Batchelder