gear-lib
Version:
Collection of common Gear.js tasks
1,178 lines (1,071 loc) • 222 kB
JavaScript
define('jslint/lib/linter', ['require', 'exports'], function(require, exports) {
// jslint.js
// 2012-05-09
// Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// The Software shall be used for Good, not Evil.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// WARNING: JSLint will hurt your feelings.
// JSLINT is a global function. It takes two parameters.
// var myResult = JSLINT(source, option);
// The first parameter is either a string or an array of strings. If it is a
// string, it will be split on '\n' or '\r'. If it is an array of strings, it
// is assumed that each string represents one line. The source can be a
// JavaScript text, or HTML text, or a JSON text, or a CSS text.
// The second parameter is an optional object of options that control the
// operation of JSLINT. Most of the options are booleans: They are all
// optional and have a default value of false. One of the options, predef,
// can be an array of names, which will be used to declare global variables,
// or an object whose keys are used as global names, with a boolean value
// that determines if they are assignable.
// If it checks out, JSLINT returns true. Otherwise, it returns false.
// If false, you can inspect JSLINT.errors to find out the problems.
// JSLINT.errors is an array of objects containing these properties:
// {
// line : The line (relative to 0) at which the lint was found
// character : The character (relative to 0) at which the lint was found
// reason : The problem
// evidence : The text line in which the problem occurred
// raw : The raw message before the details were inserted
// a : The first detail
// b : The second detail
// c : The third detail
// d : The fourth detail
// }
// If a stopping error was found, a null will be the last element of the
// JSLINT.errors array. A stopping error means that JSLint was not confident
// enough to continue. It does not necessarily mean that the error was
// especially heinous.
// You can request a data structure that contains JSLint's results.
// var myData = JSLINT.data();
// It returns a structure with this form:
// {
// errors: [
// {
// line: NUMBER,
// character: NUMBER,
// reason: STRING,
// evidence: STRING
// }
// ],
// functions: [
// {
// name: STRING,
// line: NUMBER,
// last: NUMBER,
// params: [
// {
// string: STRING
// }
// ],
// closure: [
// STRING
// ],
// var: [
// STRING
// ],
// exception: [
// STRING
// ],
// outer: [
// STRING
// ],
// unused: [
// STRING
// ],
// undef: [
// STRING
// ],
// global: [
// STRING
// ],
// label: [
// STRING
// ]
// }
// ],
// globals: [
// STRING
// ],
// member: {
// STRING: NUMBER
// },
// urls: [
// STRING
// ],
// json: BOOLEAN
// }
// Empty arrays will not be included.
// You can request a Function Report, which shows all of the functions
// and the parameters and vars that they use. This can be used to find
// implied global variables and other problems. The report is in HTML and
// can be inserted in an HTML <body>. It should be given the result of the
// JSLINT.data function.
// var myReport = JSLINT.report(data);
// You can request an HTML error report.
// var myErrorReport = JSLINT.error_report(data);
// You can request a properties report, which produces a list of the program's
// properties in the form of a /*properties*/ declaration.
// var myPropertyReport = properties_report(JSLINT.property);
// You can obtain the parse tree that JSLint constructed while parsing. The
// latest tree is kept in JSLINT.tree. A nice stringication can be produced
// with
// JSON.stringify(JSLINT.tree, [
// 'string', 'arity', 'name', 'first',
// 'second', 'third', 'block', 'else'
// ], 4));
// JSLint provides three directives. They look like slashstar comments, and
// allow for setting options, declaring global variables, and establishing a
// set of allowed property names.
// These directives respect function scope.
// The jslint directive is a special comment that can set one or more options.
// The current option set is
// anon true, if the space may be omitted in anonymous function declarations
// bitwise true, if bitwise operators should be allowed
// browser true, if the standard browser globals should be predefined
// cap true, if upper case HTML should be allowed
// 'continue' true, if the continuation statement should be tolerated
// css true, if CSS workarounds should be tolerated
// debug true, if debugger statements should be allowed
// devel true, if logging should be allowed (console, alert, etc.)
// eqeq true, if == should be allowed
// es5 true, if ES5 syntax should be allowed
// evil true, if eval should be allowed
// forin true, if for in statements need not filter
// fragment true, if HTML fragments should be allowed
// indent the indentation factor
// maxerr the maximum number of errors to allow
// maxlen the maximum length of a source line
// newcap true, if constructor names capitalization is ignored
// node true, if Node.js globals should be predefined
// nomen true, if names may have dangling _
// on true, if HTML event handlers should be allowed
// passfail true, if the scan should stop on first error
// plusplus true, if increment/decrement should be allowed
// properties true, if all property names must be declared with /*properties*/
// regexp true, if the . should be allowed in regexp literals
// rhino true, if the Rhino environment globals should be predefined
// undef true, if variables can be declared out of order
// unparam true, if unused parameters should be tolerated
// sloppy true, if the 'use strict'; pragma is optional
// stupid true, if really stupid practices are tolerated
// sub true, if all forms of subscript notation are tolerated
// vars true, if multiple var statements per function should be allowed
// white true, if sloppy whitespace is tolerated
// windows true, if MS Windows-specific globals should be predefined
// For example:
/*jslint
evil: true, nomen: true, regexp: true
*/
// The properties directive declares an exclusive list of property names.
// Any properties named in the program that are not in the list will
// produce a warning.
// For example:
/*properties
'\b', '\t', '\n', '\f', '\r', '!', '!=', '!==', '"', '%', '\'',
'(arguments)', '(begin)', '(breakage)', '(context)', '(error)',
'(identifier)', '(line)', '(loopage)', '(name)', '(params)', '(scope)',
'(token)', '(vars)', '(verb)', '*', '+', '-', '/', '<', '<=', '==', '===',
'>', '>=', ADSAFE, Array, Date, Function, Object, '\\', a, a_label,
a_not_allowed, a_not_defined, a_scope, abbr, acronym, address, adsafe,
adsafe_a, adsafe_autocomplete, adsafe_bad_id, adsafe_div, adsafe_fragment,
adsafe_go, adsafe_html, adsafe_id, adsafe_id_go, adsafe_lib,
adsafe_lib_second, adsafe_missing_id, adsafe_name_a, adsafe_placement,
adsafe_prefix_a, adsafe_script, adsafe_source, adsafe_subscript_a,
adsafe_tag, all, already_defined, and, anon, applet, apply, approved, area,
arity, article, aside, assign, assign_exception,
assignment_function_expression, at, attribute_case_a, audio, autocomplete,
avoid_a, b, background, 'background-attachment', 'background-color',
'background-image', 'background-position', 'background-repeat',
bad_assignment, bad_color_a, bad_constructor, bad_entity, bad_html, bad_id_a,
bad_in_a, bad_invocation, bad_name_a, bad_new, bad_number, bad_operand,
bad_style, bad_type, bad_url_a, bad_wrap, base, bdo, big, bitwise, block,
blockquote, body, border, 'border-bottom', 'border-bottom-color',
'border-bottom-left-radius', 'border-bottom-right-radius',
'border-bottom-style', 'border-bottom-width', 'border-collapse',
'border-color', 'border-left', 'border-left-color', 'border-left-style',
'border-left-width', 'border-radius', 'border-right', 'border-right-color',
'border-right-style', 'border-right-width', 'border-spacing', 'border-style',
'border-top', 'border-top-color', 'border-top-left-radius',
'border-top-right-radius', 'border-top-style', 'border-top-width',
'border-width', bottom, 'box-shadow', br, braille, browser, button, c, call,
canvas, cap, caption, 'caption-side', center, charAt, charCodeAt, character,
cite, clear, clip, closure, cm, code, col, colgroup, color, combine_var,
command, conditional_assignment, confusing_a, confusing_regexp,
constructor_name_a, content, continue, control_a, 'counter-increment',
'counter-reset', create, css, cursor, d, dangerous_comment, dangling_a, data,
datalist, dd, debug, del, deleted, details, devel, dfn, dialog, dir,
direction, display, disrupt, div, dl, dt, duplicate_a, edge, edition, else,
em, embed, embossed, empty, 'empty-cells', empty_block, empty_case,
empty_class, entityify, eqeq, error_report, errors, es5, eval, evidence,
evil, ex, exception, exec, expected_a, expected_a_at_b_c, expected_a_b,
expected_a_b_from_c_d, expected_at_a, expected_attribute_a,
expected_attribute_value_a, expected_class_a, expected_fraction_a,
expected_id_a, expected_identifier_a, expected_identifier_a_reserved,
expected_lang_a, expected_linear_a, expected_media_a, expected_name_a,
expected_nonstandard_style_attribute, expected_number_a, expected_operator_a,
expected_percent_a, expected_positive_a, expected_pseudo_a,
expected_selector_a, expected_small_a, expected_space_a_b, expected_string_a,
expected_style_attribute, expected_style_pattern, expected_tagname_a,
expected_type_a, f, fieldset, figure, filter, first, flag, float, floor,
font, 'font-family', 'font-size', 'font-size-adjust', 'font-stretch',
'font-style', 'font-variant', 'font-weight', footer, forEach, for_if, forin,
form, fragment, frame, frameset, from, fromCharCode, fud, funct, function,
function_block, function_eval, function_loop, function_statement,
function_strict, functions, global, globals, h1, h2, h3, h4, h5, h6,
handheld, hasOwnProperty, head, header, height, hgroup, hr,
'hta:application', html, html_confusion_a, html_handlers, i, id, identifier,
identifier_function, iframe, img, immed, implied_evil, in, indent, indexOf,
infix_in, init, input, ins, insecure_a, isAlpha, isArray, isDigit, isNaN,
join, jslint, json, kbd, keygen, keys, label, labeled, lang, lbp,
leading_decimal_a, led, left, legend, length, 'letter-spacing', li, lib,
line, 'line-height', link, 'list-style', 'list-style-image',
'list-style-position', 'list-style-type', map, margin, 'margin-bottom',
'margin-left', 'margin-right', 'margin-top', mark, 'marker-offset', match,
'max-height', 'max-width', maxerr, maxlen, menu, message, meta, meter,
'min-height', 'min-width', missing_a, missing_a_after_b, missing_option,
missing_property, missing_space_a_b, missing_url, missing_use_strict, mixed,
mm, mode, move_invocation, move_var, n, name, name_function, nav,
nested_comment, newcap, node, noframes, nomen, noscript, not,
not_a_constructor, not_a_defined, not_a_function, not_a_label, not_a_scope,
not_greater, nud, number, object, octal_a, ol, on, opacity, open, optgroup,
option, outer, outline, 'outline-color', 'outline-style', 'outline-width',
output, overflow, 'overflow-x', 'overflow-y', p, padding, 'padding-bottom',
'padding-left', 'padding-right', 'padding-top', 'page-break-after',
'page-break-before', param, parameter_a_get_b, parameter_arguments_a,
parameter_set_a, params, paren, parent, passfail, pc, plusplus, pop,
position, postscript, pre, predef, print, progress, projection, properties,
properties_report, property, prototype, pt, push, px, q, quote, quotes, r,
radix, range, raw, read_only, reason, redefinition_a, regexp, replace,
report, reserved, reserved_a, rhino, right, rp, rt, ruby, safe, samp,
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,
weird_relation, weird_ternary, white, 'white-space', width, windows,
'word-spacing', 'word-wrap', wrap, wrap_immediate, wrap_regexp,
write_is_wrong, writeable, 'z-index'
*/
// The global directive is used to declare global variables that can
// be accessed by the program. If a declaration is true, then the variable
// is writeable. Otherwise, it is read-only.
// We build the application inside a function so that we produce only a single
// global variable. That function will be invoked immediately, and its return
// value is the JSLINT function itself. That function is also an object that
// can contain data and other functions.
var JSLINT = (function () {
'use strict';
function array_to_object(array, value) {
// Make an object from an array of keys and a common value.
var i, length = array.length, object = {};
for (i = 0; i < length; i += 1) {
object[array[i]] = value;
}
return object;
}
var adsafe_id, // The widget's ADsafe id.
adsafe_may, // The widget may load approved scripts.
adsafe_top, // At the top of the widget script.
adsafe_went, // ADSAFE.go has been called.
allowed_option = {
anon : true,
bitwise : true,
browser : true,
cap : true,
'continue': true,
css : true,
debug : true,
devel : true,
eqeq : true,
es5 : true,
evil : true,
forin : true,
fragment : true,
indent : 10,
maxerr : 1000,
maxlen : 256,
newcap : true,
node : true,
nomen : true,
on : true,
passfail : true,
plusplus : true,
properties: true,
regexp : true,
rhino : true,
undef : true,
unparam : true,
sloppy : true,
stupid : true,
sub : true,
vars : true,
white : true,
windows : true
},
anonname, // The guessed name for anonymous functions.
approved, // ADsafe approved urls.
// These are operators that should not be used with the ! operator.
bang = {
'<' : true,
'<=' : true,
'==' : true,
'===': true,
'!==': true,
'!=' : true,
'>' : true,
'>=' : true,
'+' : true,
'-' : true,
'*' : true,
'/' : true,
'%' : true
},
// These are property names that should not be permitted in the safe subset.
banned = array_to_object([
'arguments', 'callee', 'caller', 'constructor', 'eval', 'prototype',
'stack', 'unwatch', 'valueOf', 'watch'
], true),
begin, // The root token
// browser contains a set of global names that are commonly provided by a
// web browser environment.
browser = array_to_object([
'clearInterval', 'clearTimeout', 'document', 'event', 'FormData',
'frames', 'history', 'Image', 'localStorage', 'location', 'name',
'navigator', 'Option', 'parent', 'screen', 'sessionStorage',
'setInterval', 'setTimeout', 'Storage', 'window', 'XMLHttpRequest'
], false),
// bundle contains the text messages.
bundle = {
a_label: "'{a}' is a statement label.",
a_not_allowed: "'{a}' is not allowed.",
a_not_defined: "'{a}' is not defined.",
a_scope: "'{a}' used out of scope.",
adsafe_a: "ADsafe violation: '{a}'.",
adsafe_autocomplete: "ADsafe autocomplete violation.",
adsafe_bad_id: "ADSAFE violation: bad id.",
adsafe_div: "ADsafe violation: Wrap the widget in a div.",
adsafe_fragment: "ADSAFE: Use the fragment option.",
adsafe_go: "ADsafe violation: Misformed ADSAFE.go.",
adsafe_html: "Currently, ADsafe does not operate on whole HTML " +
"documents. It operates on <div> fragments and .js files.",
adsafe_id: "ADsafe violation: id does not match.",
adsafe_id_go: "ADsafe violation: Missing ADSAFE.id or ADSAFE.go.",
adsafe_lib: "ADsafe lib violation.",
adsafe_lib_second: "ADsafe: The second argument to lib must be a function.",
adsafe_missing_id: "ADSAFE violation: missing ID_.",
adsafe_name_a: "ADsafe name violation: '{a}'.",
adsafe_placement: "ADsafe script placement violation.",
adsafe_prefix_a: "ADsafe violation: An id must have a '{a}' prefix",
adsafe_script: "ADsafe script violation.",
adsafe_source: "ADsafe unapproved script source.",
adsafe_subscript_a: "ADsafe subscript '{a}'.",
adsafe_tag: "ADsafe violation: Disallowed tag '{a}'.",
already_defined: "'{a}' is already defined.",
and: "The '&&' subexpression should be wrapped in parens.",
assign_exception: "Do not assign to the exception parameter.",
assignment_function_expression: "Expected an assignment or " +
"function call and instead saw an expression.",
attribute_case_a: "Attribute '{a}' not all lower case.",
avoid_a: "Avoid '{a}'.",
bad_assignment: "Bad assignment.",
bad_color_a: "Bad hex color '{a}'.",
bad_constructor: "Bad constructor.",
bad_entity: "Bad entity.",
bad_html: "Bad HTML string",
bad_id_a: "Bad id: '{a}'.",
bad_in_a: "Bad for in variable '{a}'.",
bad_invocation: "Bad invocation.",
bad_name_a: "Bad name: '{a}'.",
bad_new: "Do not use 'new' for side effects.",
bad_number: "Bad number '{a}'.",
bad_operand: "Bad operand.",
bad_style: "Bad style.",
bad_type: "Bad type.",
bad_url_a: "Bad url '{a}'.",
bad_wrap: "Do not wrap function literals in parens unless they " +
"are to be immediately invoked.",
combine_var: "Combine this with the previous 'var' statement.",
conditional_assignment: "Expected a conditional expression and " +
"instead saw an assignment.",
confusing_a: "Confusing use of '{a}'.",
confusing_regexp: "Confusing regular expression.",
constructor_name_a: "A constructor name '{a}' should start with " +
"an uppercase letter.",
control_a: "Unexpected control character '{a}'.",
css: "A css file should begin with @charset 'UTF-8';",
dangling_a: "Unexpected dangling '_' in '{a}'.",
dangerous_comment: "Dangerous comment.",
deleted: "Only properties should be deleted.",
duplicate_a: "Duplicate '{a}'.",
empty_block: "Empty block.",
empty_case: "Empty case.",
empty_class: "Empty class.",
es5: "This is an ES5 feature.",
evil: "eval is evil.",
expected_a: "Expected '{a}'.",
expected_a_b: "Expected '{a}' and instead saw '{b}'.",
expected_a_b_from_c_d: "Expected '{a}' to match '{b}' from line " +
"{c} and instead saw '{d}'.",
expected_at_a: "Expected an at-rule, and instead saw @{a}.",
expected_a_at_b_c: "Expected '{a}' at column {b}, not column {c}.",
expected_attribute_a: "Expected an attribute, and instead saw [{a}].",
expected_attribute_value_a: "Expected an attribute value and " +
"instead saw '{a}'.",
expected_class_a: "Expected a class, and instead saw .{a}.",
expected_fraction_a: "Expected a number between 0 and 1 and " +
"instead saw '{a}'",
expected_id_a: "Expected an id, and instead saw #{a}.",
expected_identifier_a: "Expected an identifier and instead saw '{a}'.",
expected_identifier_a_reserved: "Expected an identifier and " +
"instead saw '{a}' (a reserved word).",
expected_linear_a: "Expected a linear unit and instead saw '{a}'.",
expected_lang_a: "Expected a lang code, and instead saw :{a}.",
expected_media_a: "Expected a CSS media type, and instead saw '{a}'.",
expected_name_a: "Expected a name and instead saw '{a}'.",
expected_nonstandard_style_attribute: "Expected a non-standard " +
"style attribute and instead saw '{a}'.",
expected_number_a: "Expected a number and instead saw '{a}'.",
expected_operator_a: "Expected an operator and instead saw '{a}'.",
expected_percent_a: "Expected a percentage and instead saw '{a}'",
expected_positive_a: "Expected a positive number and instead saw '{a}'",
expected_pseudo_a: "Expected a pseudo, and instead saw :{a}.",
expected_selector_a: "Expected a CSS selector, and instead saw {a}.",
expected_small_a: "Expected a small positive integer and instead saw '{a}'",
expected_space_a_b: "Expected exactly one space between '{a}' and '{b}'.",
expected_string_a: "Expected a string and instead saw {a}.",
expected_style_attribute: "Excepted a style attribute, and instead saw '{a}'.",
expected_style_pattern: "Expected a style pattern, and instead saw '{a}'.",
expected_tagname_a: "Expected a tagName, and instead saw {a}.",
expected_type_a: "Expected a type, and instead saw {a}.",
for_if: "The body of a for in should be wrapped in an if " +
"statement to filter unwanted properties from the prototype.",
function_block: "Function statements should not be placed in blocks. " +
"Use a function expression or move the statement to the top of " +
"the outer function.",
function_eval: "The Function constructor is eval.",
function_loop: "Don't make functions within a loop.",
function_statement: "Function statements are not invocable. " +
"Wrap the whole function invocation in parens.",
function_strict: "Use the function form of 'use strict'.",
html_confusion_a: "HTML confusion in regular expression '<{a}'.",
html_handlers: "Avoid HTML event handlers.",
identifier_function: "Expected an identifier in an assignment " +
"and instead saw a function invocation.",
implied_evil: "Implied eval is evil. Pass a function instead of a string.",
infix_in: "Unexpected 'in'. Compare with undefined, or use the " +
"hasOwnProperty method instead.",
insecure_a: "Insecure '{a}'.",
isNaN: "Use the isNaN function to compare with NaN.",
lang: "lang is deprecated.",
leading_decimal_a: "A leading decimal point can be confused with a dot: '.{a}'.",
missing_a: "Missing '{a}'.",
missing_a_after_b: "Missing '{a}' after '{b}'.",
missing_option: "Missing option value.",
missing_property: "Missing property name.",
missing_space_a_b: "Missing space between '{a}' and '{b}'.",
missing_url: "Missing url.",
missing_use_strict: "Missing 'use strict' statement.",
mixed: "Mixed spaces and tabs.",
move_invocation: "Move the invocation into the parens that " +
"contain the function.",
move_var: "Move 'var' declarations to the top of the function.",
name_function: "Missing name in function statement.",
nested_comment: "Nested comment.",
not: "Nested not.",
not_a_constructor: "Do not use {a} as a constructor.",
not_a_defined: "'{a}' has not been fully defined yet.",
not_a_function: "'{a}' is not a function.",
not_a_label: "'{a}' is not a label.",
not_a_scope: "'{a}' is out of scope.",
not_greater: "'{a}' should not be greater than '{b}'.",
octal_a: "Don't use octal: '{a}'. Use '\\u....' instead.",
parameter_arguments_a: "Do not mutate parameter '{a}' when using 'arguments'.",
parameter_a_get_b: "Unexpected parameter '{a}' in get {b} function.",
parameter_set_a: "Expected parameter (value) in set {a} function.",
radix: "Missing radix parameter.",
read_only: "Read only.",
redefinition_a: "Redefinition of '{a}'.",
reserved_a: "Reserved name '{a}'.",
scanned_a_b: "{a} ({b}% scanned).",
slash_equal: "A regular expression literal can be confused with '/='.",
statement_block: "Expected to see a statement and instead saw a block.",
stopping: "Stopping. ",
strange_loop: "Strange loop.",
strict: "Strict violation.",
subscript: "['{a}'] is better written in dot notation.",
sync_a: "Unexpected sync method: '{a}'.",
tag_a_in_b: "A '<{a}>' must be within '<{b}>'.",
too_long: "Line too long.",
too_many: "Too many errors.",
trailing_decimal_a: "A trailing decimal point can be confused " +
"with a dot: '.{a}'.",
type: "type is unnecessary.",
unclosed: "Unclosed string.",
unclosed_comment: "Unclosed comment.",
unclosed_regexp: "Unclosed regular expression.",
unescaped_a: "Unescaped '{a}'.",
unexpected_a: "Unexpected '{a}'.",
unexpected_char_a_b: "Unexpected character '{a}' in {b}.",
unexpected_comment: "Unexpected comment.",
unexpected_else: "Unexpected 'else' after 'return'.",
unexpected_label_a: "Unexpected label '{a}'.",
unexpected_property_a: "Unexpected /*property*/ '{a}'.",
unexpected_space_a_b: "Unexpected space between '{a}' and '{b}'.",
unnecessary_initialize: "It is not necessary to initialize '{a}' " +
"to 'undefined'.",
unnecessary_use: "Unnecessary 'use strict'.",
unreachable_a_b: "Unreachable '{a}' after '{b}'.",
unrecognized_style_attribute_a: "Unrecognized style attribute '{a}'.",
unrecognized_tag_a: "Unrecognized tag '<{a}>'.",
unsafe: "Unsafe character.",
url: "JavaScript URL.",
use_array: "Use the array literal notation [].",
use_braces: "Spaces are hard to count. Use {{a}}.",
use_charAt: "Use the charAt method.",
use_object: "Use the object literal notation {}.",
use_or: "Use the || operator.",
use_param: "Use a named parameter.",
used_before_a: "'{a}' was used before it was defined.",
var_a_not: "Variable {a} was not declared correctly.",
weird_assignment: "Weird assignment.",
weird_condition: "Weird condition.",
weird_new: "Weird construction. Delete 'new'.",
weird_program: "Weird program.",
weird_relation: "Weird relation.",
weird_ternary: "Weird ternary.",
wrap_immediate: "Wrap an immediate function invocation in parentheses " +
"to assist the reader in understanding that the expression " +
"is the result of a function, and not the function itself.",
wrap_regexp: "Wrap the /regexp/ literal in parens to " +
"disambiguate the slash operator.",
write_is_wrong: "document.write can be a form of eval."
},
comments_off,
css_attribute_data,
css_any,
css_colorData = array_to_object([
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral",
"cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue",
"darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki",
"darkmagenta", "darkolivegreen", "darkorange", "darkorchid",
"darkred", "darksalmon", "darkseagreen", "darkslateblue",
"darkslategray", "darkturquoise", "darkviolet", "deeppink",
"deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite",
"forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold",
"goldenrod", "gray", "green", "greenyellow", "honeydew", "hotpink",
"indianred", "indigo", "ivory", "khaki", "lavender",
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue",
"lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgreen",
"lightpink", "lightsalmon", "lightseagreen", "lightskyblue",
"lightslategray", "lightsteelblue", "lightyellow", "lime",
"limegreen", "linen", "magenta", "maroon", "mediumaquamarine",
"mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen",
"mediumslateblue", "mediumspringgreen", "mediumturquoise",
"mediumvioletred", "midnightblue", "mintcream", "mistyrose",
"moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab",
"orange", "orangered", "orchid", "palegoldenrod", "palegreen",
"paleturquoise", "palevioletred", "papayawhip", "peachpuff",
"peru", "pink", "plum", "powderblue", "purple", "red", "rosybrown",
"royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen",
"seashell", "sienna", "silver", "skyblue", "slateblue", "slategray",
"snow", "springgreen", "steelblue", "tan", "teal", "thistle",
"tomato", "turquoise", "violet", "wheat", "white", "whitesmoke",
"yellow", "yellowgreen",
"activeborder", "activecaption", "appworkspace", "background",
"buttonface", "buttonhighlight", "buttonshadow", "buttontext",
"captiontext", "graytext", "highlight", "highlighttext",
"inactiveborder", "inactivecaption", "inactivecaptiontext",
"infobackground", "infotext", "menu", "menutext", "scrollbar",
"threeddarkshadow", "threedface", "threedhighlight",
"threedlightshadow", "threedshadow", "window", "windowframe",
"windowtext"
], true),
css_border_style,
css_break,
css_lengthData = {
'%': true,
'cm': true,
'em': true,
'ex': true,
'in': true,
'mm': true,
'pc': true,
'pt': true,
'px': true
},
css_media,
css_overflow,
descapes = {
'b': '\b',
't': '\t',
'n': '\n',
'f': '\f',
'r': '\r',
'"': '"',
'/': '/',
'\\': '\\',
'!': '!'
},
devel = array_to_object([
'alert', 'confirm', 'console', 'Debug', 'opera', 'prompt', 'WSH'
], false),
directive,
escapes = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'\'': '\\\'',
'"' : '\\"',
'/' : '\\/',
'\\': '\\\\'
},
funct, // The current function, including the labels used in
// the function, as well as (breakage),
// (context), (loopage), (name), (params), (token),
// (vars), (verb)
functionicity = [
'closure', 'exception', 'global', 'label', 'outer', 'undef',
'unused', 'var'
],
functions, // All of the functions
global_funct, // The global body
global_scope, // The global scope
html_tag = {
a: {},
abbr: {},
acronym: {},
address: {},
applet: {},
area: {empty: true, parent: ' map '},
article: {},
aside: {},
audio: {},
b: {},
base: {empty: true, parent: ' head '},
bdo: {},
big: {},
blockquote: {},
body: {parent: ' html noframes '},
br: {empty: true},
button: {},
canvas: {parent: ' body p div th td '},
caption: {parent: ' table '},
center: {},
cite: {},
code: {},
col: {empty: true, parent: ' table colgroup '},
colgroup: {parent: ' table '},
command: {parent: ' menu '},
datalist: {},
dd: {parent: ' dl '},
del: {},
details: {},
dialog: {},
dfn: {},
dir: {},
div: {},
dl: {},
dt: {parent: ' dl '},
em: {},
embed: {},
fieldset: {},
figure: {},
font: {},
footer: {},
form: {},
frame: {empty: true, parent: ' frameset '},
frameset: {parent: ' html frameset '},
h1: {},
h2: {},
h3: {},
h4: {},
h5: {},
h6: {},
head: {parent: ' html '},
header: {},
hgroup: {},
hr: {empty: true},
'hta:application':
{empty: true, parent: ' head '},
html: {parent: '*'},
i: {},
iframe: {},
img: {empty: true},
input: {empty: true},
ins: {},
kbd: {},
keygen: {},
label: {},
legend: {parent: ' details fieldset figure '},
li: {parent: ' dir menu ol ul '},
link: {empty: true, parent: ' head '},
map: {},
mark: {},
menu: {},
meta: {empty: true, parent: ' head noframes noscript '},
meter: {},
nav: {},
noframes: {parent: ' html body '},
noscript: {parent: ' body head noframes '},
object: {},
ol: {},
optgroup: {parent: ' select '},
option: {parent: ' optgroup select '},
output: {},
p: {},
param: {empty: true, parent: ' applet object '},
pre: {},
progress: {},
q: {},
rp: {},
rt: {},
ruby: {},
samp: {},
script: {empty: true, parent: ' body div frame head iframe p pre span '},
section: {},
select: {},
small: {},
span: {},
source: {},
strong: {},
style: {parent: ' head ', empty: true},
sub: {},
sup: {},
table: {},
tbody: {parent: ' table '},
td: {parent: ' tr '},
textarea: {},
tfoot: {parent: ' table '},
th: {parent: ' tr '},
thead: {parent: ' table '},
time: {},
title: {parent: ' head '},
tr: {parent: ' table tbody thead tfoot '},
tt: {},
u: {},
ul: {},
'var': {},
video: {}
},
ids, // HTML ids
in_block,
indent,
itself, // JSLint itself
json_mode,
lex, // the tokenizer
lines,
lookahead,
node = array_to_object([
'Buffer', 'clearInterval', 'clearTimeout', 'console', 'exports',
'global', 'module', 'process', 'querystring', 'require',
'setInterval', 'setTimeout', '__dirname', '__filename'
], false),
node_js,
numbery = array_to_object(['indexOf', 'lastIndexOf', 'search'], true),
next_token,
option,
predefined, // Global variables defined by option
prereg,
prev_token,
property,
regexp_flag = array_to_object(['g', 'i', 'm'], true),
return_this = function return_this() {
return this;
},
rhino = array_to_object([
'defineClass', 'deserialize', 'gc', 'help', 'load', 'loadClass',
'print', 'quit', 'readFile', 'readUrl', 'runCommand', 'seal',
'serialize', 'spawn', 'sync', 'toint32', 'version'
], false),
scope, // An object containing an object for each variable in scope
semicolon_coda = array_to_object([';', '"', '\'', ')'], true),
src,
stack,
// standard contains the global names that are provided by the
// ECMAScript standard.
standard = array_to_object([
'Array', 'Boolean', 'Date', 'decodeURI', 'decodeURIComponent',
'encodeURI', 'encodeURIComponent', 'Error', 'eval', 'EvalError',
'Function', 'isFinite', 'isNaN', 'JSON', 'Math', 'Number',
'Object', 'parseInt', 'parseFloat', 'RangeError', 'ReferenceError',
'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError'
], false),
strict_mode,
syntax = {},
tab,
token,
urls,
var_mode,
warnings,
windows = array_to_object([
'ActiveXObject', 'CScript', 'Debug', 'Enumerator', 'System',
'VBArray', 'WScript', 'WSH'
], false),
// xmode is used to adapt to the exceptions in html parsing.
// It can have these states:
// '' .js script file
// 'html'
// 'outer'
// 'script'
// 'style'
// 'scriptstring'
// 'styleproperty'
xmode,
xquote,
// Regular expressions. Some of these are stupidly long.
// unsafe comment or string
ax = /@cc|<\/?|script|\]\s*\]|<\s*!|</i,
// carriage return, carriage return linefeed, or linefeed
crlfx = /\r\n?|\n/,
// unsafe characters that are silently deleted by one or more browsers
cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
// query characters for ids
dx = /[\[\]\/\\"'*<>.&:(){}+=#]/,
// html token
hx = /^\s*(['"=>\/&#]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-:]*|[0-9]+|--)/,
// identifier
ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/,
// javascript url
jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i,
// star slash
lx = /\*\/|\/\*/,
// characters in strings that need escapement
nx = /[\u0000-\u001f'\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
// outer html token
ox = /[>&]|<[\/!]?|--/,
// attributes characters
qx = /[^a-zA-Z0-9+\-_\/. ]/,
// style
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]+)?)/,
// url badness
ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto|script/i,
rx = {
outer: hx,
html: hx,
style: sx,
styleproperty: ssx
};
function F() {} // Used by Object.create
// Provide critical ES5 functions to ES3.
if (typeof Array.prototype.filter !== 'function') {
Array.prototype.filter = function (f) {
var i, length = this.length, result = [], value;
for (i = 0; i < length; i += 1) {
try {
value = this[i];
if (f(value)) {
result.push(value);
}
} catch (ignore) {
}
}
return result;
};
}
if (typeof Array.prototype.forEach !== 'function') {
Array.prototype.forEach = function (f) {
var i, length = this.length;
for (i = 0; i < length; i += 1) {
try {
f(this[i]);
} catch (ignore) {
}
}
};
}
if (typeof Array.isArray !== 'function') {
Array.isArray = function (o) {
return Object.prototype.toString.apply(o) === '[object Array]';
};
}
if (!Object.prototype.hasOwnProperty.call(Object, 'create')) {
Object.create = function (o) {
F.prototype = o;
return new F();
};
}
if (typeof Object.keys !== 'function') {
Object.keys = function (o) {
var array = [], key;
for (key in o) {
if (Object.prototype.hasOwnProperty.call(o, key)) {
array.push(key);
}
}
return array;
};
}
if (typeof String.prototype.entityify !== 'function') {
String.prototype.entityify = function () {
return this
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
};
}
if (typeof String.prototype.isAlpha !== 'function') {
String.prototype.isAlpha = function () {
return (this >= 'a' && this <= 'z\uffff') ||
(this >= 'A' && this <= 'Z\uffff');
};
}
if (typeof String.prototype.isDigit !== 'function') {
String.prototype.isDigit = function () {
return (this >= '0' && this <= '9');
};
}
if (typeof String.prototype.supplant !== 'function') {
String.prototype.supplant = function (o) {
return this.replace(/\{([^{}]*)\}/g, function (a, b) {
var replacement = o[b];
return typeof replacement === 'string' ||
typeof replacement === 'number' ? replacement : a;
});
};
}
function sanitize(a) {
// Escapify a troublesome character.
return escapes[a] ||
'\\u' + ('0000' + a.charCodeAt().toString(16)).slice(-4);
}
function add_to_predefined(group) {
Object.keys(group).forEach(function (name) {
predefined[name] = group[name];
});
}
function assume() {
if (!option.safe) {
if (option.rhino) {
add_to_predefined(rhino);
option.rhino = false;
}
if (option.devel) {
add_to_predefined(devel);
option.devel = false;
}
if (option.browser) {
add_to_predefined(browser);
option.browser = false;
}
if (option.windows) {
add_to_predefined(windows);
option.windows = false;
}
if (option.node) {
add_to_predefined(node);
option.node = false;
node_js = true;
}
}
}
// Produce an error warning.
function artifact(tok) {
if (!tok) {
tok = next_token;
}
return tok.number || tok.string;
}
function quit(message, line, character) {
throw {
name: 'JSLintError',
line: line,
character: character,
message: bundle.scanned_a_b.supplant({
a: message,
b: Math.floor((line / lines.length) * 100)
})
};
}
function warn(message, offender, a, b, c, d) {
var character, line, warning;
offender = offender || next_token; // ~~
line = offender.line || 0;
character = offender.from || 0;
warning = {
id: '(error)',
raw: bundle[message] || message,
evidence: lines[line - 1] || '',
line: line,
character: character,
a: a || (offender.id === '(number)'
? String(offender.number)
: offender.string),
b: b,
c: c,
d: d
};
warning.reason = warning.raw.supplant(warning);
JSLINT.errors.push(warning);
if (option.passfail) {
quit(bundle.stopping, line, character);
}
warnings += 1;
if (warnings >= option.maxerr) {
quit(bundle.too_many, line, character);
}
return warning;
}
function warn_at(message, line, character, a, b, c, d) {
return 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);
}
function stop_at(message, line, character, a, b, c, d) {
return stop(message, {
line: line,
from: character
}, a, b, c, d);
}
function expected_at(at) {
if (!option.white && next_token.from !== at) {
warn('expected_a_at_b_c', next_token, '', at,
next_token.from);
}
}
function aint(it, name, expected) {
if (it[name] !== expected) {
warn('expected_a_b', it, expected, it[name]);
return true;
}
return false;
}
// lexical analysis and token construction
lex = (function lex() {