-
Notifications
You must be signed in to change notification settings - Fork 38
jQuery Lint exposes itself under the jQuery
namespace as LINT
:
jQuery.LINT;
You have direct access to the API data:
jQuery.LINT.api;
This is an object, each property refers to a jQuery function/method.
jQuery.LINT.api.jQuery; // jQuery function jQuery.LINT.api.css; // css method jQuery.LINT.api['jQuery.extend']; // extend helper function
If you want to add some custom checks to Lint you’ll probably want to do this via special
instead of manipulating the api data directly.
As explained already on the Error Reports page, there are four error reporting levels (strictly, three, because zero means everything is off). You can add a custom check under any of these levels:
// Add css method check (err reporting lvl: 3) jQuery.LINT.special[3].css = [function() { if (!condition_to_see_if_it_passes) { return "You did something wrong!\nMore info:\nBlah blah blah"; } }];
Make sure that you’re not overwriting any pre-existing special checks though. Currently there aren’t any that come with jQuery Lint but still, it’s something to be aware of (potentially, in the future, there might be some default checks). Each method, under each error-reporting level, can have its checks stored in an array. Another example:
// Defining multiple checks. var lintSpecialChecksLvl1 = jQuery.LINT.special[1], ajaxMethodChecks = ['jQuery.ajax'] = (lintSpecialChecksLvl1 || []); ajaxMethodChecks.push(function(){ /* Do check */ }); ajaxMethodChecks.push(function(){ /* Do check */ }); ajaxMethodChecks.push(function(){ /* Do check */ });
This is a little better than just blindly defining a new array of checks. Here we’re checking whether one already exists and if it doesn’t we’re defining a new array (lintSpecialChecksLvl1 || []
). Then we’re pushing to the array. This’ll make sure that we’re not wiping any already-existing checks.
You can also access and manipulate the console mecahnism used by jQuery Lint, via jQuery.LINT.console
. E.g.
var warningContainer = $('#warning'); jQuery.LINT.console.warn = function(msg) { warningContainer.append(msg + '<br/>'); };
Typically, you won’t need to do this. The checks done by Lint are browser agnostic, and the reporting mechanism works best in Firefox (Firebug). You should only need to define your own console if you’re developing under a different browser. jQuery Lint, by default, will silently fail in browsers that don’t support its default console mechanism. From the source:
_console = { warn: glob.console && console.warn ? function(){return console.warn.apply(console, arguments);} : function(){}, group: glob.console && console.group ? function(){return console.group.apply(console, arguments);} : function(){}, groupEnd: glob.console && console.groupEnd ? function(){return console.groupEnd.apply(console, arguments);} : function(){}, groupCollapsed: glob.console && console.groupCollapsed ? function(){return console.groupCollapsed.apply(console, arguments);} : function(){}, log: glob.console && console.log ? function(){return console.log.apply(console, arguments);} : function(){} },