"Suppress messages" feature for JSLint #131

Closed
wants to merge 10 commits into
from
View
@@ -289,20 +289,20 @@
scanned_a_b, screen, script, search, second, section, select, shift,
slash_equal, slice, sloppy, small, sort, source, span, speech, split, src,
statement_block, stopping, strange_loop, strict, string, strong, stupid,
- style, styleproperty, sub, subscript, substr, sup, supplant, sync_a, t,
- table, 'table-layout', tag_a_in_b, tbody, td, test, 'text-align',
- 'text-decoration', 'text-indent', 'text-shadow', 'text-transform', textarea,
- tfoot, th, thead, third, thru, time, title, toLowerCase, toString,
- toUpperCase, token, too_long, too_many, top, tr, trailing_decimal_a, tree,
- tt, tty, tv, type, u, ul, unclosed, unclosed_comment, unclosed_regexp, undef,
- undefined, unescaped_a, unexpected_a, unexpected_char_a_b,
- unexpected_comment, unexpected_else, unexpected_label_a,
- unexpected_property_a, unexpected_space_a_b, 'unicode-bidi',
- unnecessary_initialize, unnecessary_use, unparam, unreachable_a_b,
- unrecognized_style_attribute_a, unrecognized_tag_a, unsafe, unused, url,
- urls, use_array, use_braces, use_charAt, use_object, use_or, use_param,
- used_before_a, var, var_a_not, vars, 'vertical-align', video, visibility,
- was, weird_assignment, weird_condition, weird_new, weird_program,
+ style, styleproperty, sub, subscript, substr, sup, supplant, suppress,
+ suppressed_messages, sync_a, t, table, 'table-layout', tag_a_in_b, tbody, td,
+ test, 'text-align', 'text-decoration', 'text-indent', 'text-shadow',
+ 'text-transform', textarea, tfoot, th, thead, third, thru, time, title,
+ toLowerCase, toString, toUpperCase, token, too_long, too_many, top, tr,
+ trailing_decimal_a, tree, tt, tty, tv, type, u, ul, unclosed,
+ unclosed_comment, unclosed_regexp, undef, undefined, unescaped_a,
+ unexpected_a, unexpected_char_a_b, unexpected_comment, unexpected_else,
+ unexpected_label_a, unexpected_property_a, unexpected_space_a_b,
+ 'unicode-bidi', unnecessary_initialize, unnecessary_use, unparam,
+ unreachable_a_b, unrecognized_style_attribute_a, unrecognized_tag_a, unsafe,
+ unused, url, urls, use_array, use_braces, use_charAt, use_object, use_or,
+ use_param, used_before_a, var, var_a_not, vars, 'vertical-align', video,
+ visibility, was, weird_assignment, weird_condition, weird_new, weird_program,
weird_relation, weird_ternary, white, 'white-space', width, windows,
'word-spacing', 'word-wrap', wrap, wrap_immediate, wrap_regexp,
write_is_wrong, writeable, 'z-index'
@@ -887,6 +887,7 @@ var JSLINT = (function () {
], false),
strict_mode,
+ suppressed_messages = {},
syntax = {},
tab,
token,
@@ -940,7 +941,7 @@ var JSLINT = (function () {
sx = /^\s*([{}:#%.=,>+\[\]@()"';]|[*$\^~]=|[a-zA-Z_][a-zA-Z0-9_\-]*|[0-9]+|<\/|\/\*)/,
ssx = /^\s*([@#!"'};:\-%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\/\*?|\d+(?:\.\d+)?|<\/)/,
// token
- tx = /^\s*([(){}\[\]\?.,:;'"~#@`]|={1,3}|\/(\*(jslint|properties|property|members?|globals?)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|[\^%]=?|&[&=]?|\|[|=]?|>{1,3}=?|<(?:[\/=!]|\!(\[|--)?|<=?)?|\!={0,2}|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+(?:[xX][0-9a-fA-F]+|\.[0-9]*)?(?:[eE][+\-]?[0-9]+)?)/,
+ tx = /^\s*([(){}\[\]\?.,:;'"~#@`]|={1,3}|\/(\*(jslint|properties|property|members?|globals?|suppress)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|[\^%]=?|&[&=]?|\|[|=]?|>{1,3}=?|<(?:[\/=!]|\!(\[|--)?|<=?)?|\!={0,2}|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+(?:[xX][0-9a-fA-F]+|\.[0-9]*)?(?:[eE][+\-]?[0-9]+)?)/,
// url badness
ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto|script/i,
@@ -1058,6 +1059,13 @@ var JSLINT = (function () {
}
+ function add_to_suppressed_messages(group) {
+ Object.keys(group).forEach(function (name) {
+ suppressed_messages[name] = group[name];
+ });
+ }
+
+
function assume() {
if (!option.safe) {
if (option.rhino) {
@@ -1106,8 +1114,11 @@ var JSLINT = (function () {
};
}
- function warn(message, offender, a, b, c, d) {
+ function do_warn(message, offender, a, b, c, d) {
var character, line, warning;
+ if (JSLINT.suppressed_messages[message] === true) {
+ return false;
+ }
offender = offender || next_token; // ~~
line = offender.line || 0;
character = offender.from || 0;
@@ -1136,20 +1147,26 @@ var JSLINT = (function () {
return warning;
}
+ function warn(message, offender, a, b, c, d) {
+ do_warn(message, offender, a, b, c, d);
+ }
+
function warn_at(message, line, character, a, b, c, d) {
- return warn(message, {
+ warn(message, {
line: line,
from: character
}, a, b, c, d);
}
function stop(message, offender, a, b, c, d) {
- var warning = warn(message, offender, a, b, c, d);
- quit(bundle.stopping, warning.line, warning.character);
+ var warning = do_warn(message, offender, a, b, c, d);
+ if (warning !== false) {
+ quit(bundle.stopping, warning.line, warning.character);
+ }
}
function stop_at(message, line, character, a, b, c, d) {
- return stop(message, {
+ stop(message, {
line: line,
from: character
}, a, b, c, d);
@@ -2144,6 +2161,38 @@ klass: do {
}
+ function do_suppresses() {
+ var name, is_suppress;
+ for (;;) {
+ if (next_token.id !== '(string)' && !next_token.identifier) {
+ return;
+ }
+ name = next_token.string;
+ advance();
+ is_suppress = true;
+ if (next_token.id === ':') {
+ advance(':');
+ switch (next_token.id) {
+ case 'true':
+ advance('true');
+ break;
+ case 'false':
+ is_suppress = false;
+ advance('false');
+ break;
+ default:
+ stop('unexpected_a');
+ }
+ }
+ suppressed_messages[name] = is_suppress;
+ if (next_token.id !== ',') {
+ return;
+ }
+ advance(',');
+ }
+ }
+
+
function do_jslint() {
var name, value;
while (next_token.id === '(string)' || next_token.identifier) {
@@ -2239,6 +2288,9 @@ klass: do {
}
do_globals();
break;
+ case '/*suppress':
+ do_suppresses();
+ break;
default:
stop('unexpected_a', this);
}
@@ -3960,6 +4012,7 @@ klass: do {
stmt('/*members', directive);
stmt('/*property', directive);
stmt('/*properties', directive);
+ stmt('/*suppress', directive);
stmt('var', function () {
@@ -5998,7 +6051,7 @@ klass: do {
itself = function JSLint(the_source, the_option) {
- var i, predef, tree;
+ var i, predef, suppress, tree;
JSLINT.errors = [];
JSLINT.tree = '';
JSLINT.properties = '';
@@ -6019,6 +6072,16 @@ klass: do {
add_to_predefined(predef);
}
}
+ suppress = option.suppress;
+ if (suppress) {
+ if (Array.isArray(suppress)) {
+ for (i = 0; i < suppress.length; i += 1) {
+ suppressed_messages[suppress[i]] = true;
+ }
+ } else if (typeof suppress === 'object') {
+ add_to_suppressed_messages(suppress);
+ }
+ }
do_safe();
} else {
option = {};
@@ -6392,6 +6455,8 @@ klass: do {
return output.join('\n');
};
+ itself.suppressed_messages = suppressed_messages;
+
itself.jslint = itself;
itself.edition = '2012-05-09';