Tip: Click lines to highlight, hold ctrl/cmd to multi-select
http://codedumper.com/ebaqo (28-Jul @ 10:24)
Syntax Highlighted Code
- // jslint.js
- // 2008-07-25
- /*
- 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.
- */
- /*
- 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 Konfabulator text.
- The second parameter is an optional object of options which control the
- operation of JSLINT. Most of the options are booleans: They are all are
- optional and have a default value of false.
- 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 members:
- {
- 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 fatal error was found, a null will be the last element of the
- JSLINT.errors array.
- 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>.
- var myReport = JSLINT.report(limited);
- If limited is true, then the report will be limited to only errors.
- */
- /*jslint evil: true, nomen: false */
- /*members "\b", "\t", "\n", "\f", "\r", "\"", "(begin)", "(breakage)",
- "(context)", "(end)", "(global)", "(identifier)", "(line)", "(loopage)",
- "(name)", "(params)", "(scope)", "(verb)", ")", "++", "--", "\/",
- ADSAFE, Array, Boolean, COM, Canvas, CustomAnimation, Date, Debug, E,
- Error, EvalError, FadeAnimation, FormField, Frame, Function, HotKey,
- Image, JSON, LN10, LN2, LOG10E, LOG2E, MAX_VALUE, MIN_VALUE, Math,
- MenuItem, MoveAnimation, NEGATIVE_INFINITY, Number, Object, Option, PI,
- POSITIVE_INFINITY, Point, RangeError, ReferenceError, RegExp,
- RotateAnimation, SQRT1_2, SQRT2, ScrollBar, String, SyntaxError, System,
- Text, TextArea, Timer, TypeError, URIError, URL, Window, XMLDOM,
- XMLHttpRequest, "\\", "]", a, abbr, "about-box", "about-image",
- "about-text", "about-version", acronym, action, address, adsafe, alert,
- alignment, anchorstyle, animator, appleScript, applet, apply, approved,
- area, arguments, author, autohide, b, background, base, bdo, beep,
- create, bgcolor, bgcolour, bgopacity, big, bitwise, block, blockquote,
- blur, body, br, browser, button, bytesToUIString, c, call, callee,
- caller, canvas, cap, caption, cases, center, charAt, charCodeAt,
- character, charset, checked, chooseColor, chooseFile, chooseFolder,
- cite, clearInterval, clearTimeout, cliprect, close, closeWidget, closed,
- code, col, colgroup, color, colorize, colour, columns, comment, company,
- condition, confirm, console, constructor, content, contextmenuitems,
- convertPathToHFS, convertPathToPlatform, copyright, d, data, dd, debug,
- decodeURI, decodeURIComponent, defaultStatus, defaulttracking,
- defaultvalue, defineClass, del, description, deserialize, dfn, dir,
- directory, div, dl, doAttribute, doBegin, doIt, doTagName, document, dt,
- dynsrc, editable, em, embed, empty, enabled, encodeURI,
- encodeURIComponent, entityify, eqeqeq, errors, escape, eval, event,
- evidence, evil, exec, exps, extension, fieldset, file, filesystem,
- fillmode, first, floor, focus, focusWidget, font, fontstyle, forin,
- form, fragment, frame, frames, frameset, from, fromCharCode, fud,
- function, g, gc, getComputedStyle, group, h1, h2, h3, h4, h5,
- h6, halign, handlelinks, hasOwnProperty, head, height, help, hidden,
- history, hlinesize, hoffset, hotkey, hr, href, hregistrationpoint,
- hscrollbar, hsladjustment, hsltinting, html, i, iTunes, icon, id,
- identifier, iframe, image, img, include, indent, indexOf, init, input,
- ins, interval, isAlpha, isApplicationRunning, isDigit, isFinite, isNaN,
- join, kbd, key, kind, konfabulatorVersion, label, labelled, laxbreak,
- lbp, led, left, legend, length, level, li, line, lines, link, load,
- loadClass, loadingsrc, location, locked, log, lowsrc, m, map, match,
- max, maxlength, menu, menuitem, message, meta, min, minimumversion,
- minlength, missingsrc, modifier, moveBy, moveTo, name, navigator, new,
- noframes, nomen, noscript, notsaved, nud, object, ol, on, onblur,
- onclick, oncontextmenu, ondragdrop, ondragenter, ondragexit, onerror,
- onfirstdisplay, onfocus, ongainfocus, onimageloaded, onkeydown,
- onkeypress, onkeyup, onload, onlosefocus, onmousedown, onmousedrag,
- onmouseenter, onmouseexit, onmousemove, onmouseup, onmousewheel,
- onmulticlick, onresize, onselect, ontextinput, ontimerfired, onunload,
- onvaluechanged, opacity, open, openURL, opener, opera, optgroup, option,
- optionvalue, order, orientation, p, pagesize, param, parent, parseFloat,
- parseInt, passfail, play, plusplus, pop, popupMenu, pre, predef,
- preference, preferenceGroups, preferencegroup, preferences, print,
- prompt, prototype, push, q, quit, random, raw, reach, readFile, readUrl,
- reason, regexp, reloadWidget, remoteasync, replace, report,
- requiredplatform, reserved, resizeBy, resizeTo, resolvePath,
- resumeUpdates, rhino, right, root, rotation, runCommand, runCommandInBg,
- safe, samp, saveAs, savePreferences, screen, script, scroll, scrollBy,
- scrollTo, scrollbar, scrolling, scrollx, scrolly, seal, search, secure,
- select, self, serialize, setInterval, setTimeout, setting, settings,
- shadow, shift, showWidgetPreferences, sidebar, size, skip, sleep, slice,
- small, sort, span, spawn, speak, special, spellcheck, split, src,
- srcheight, srcwidth, status, strong, style, sub, substr, subviews, sup,
- superview, supplant, suppressUpdates, sync, system, table, tag, tbody,
- td, tellWidget, test, text, textarea, tfoot, th, thead, thumbcolor,
- ticking, ticklabel, ticks, tileorigin, timer, title, toLowerCase,
- toString, toUpperCase, toint32, token, tooltip, top, tr, tracking,
- trigger, truncation, tt, type, u, ul, undef, unescape, union, unwatch,
- updateNow, url, usefileicon, valign, value, valueOf, var, version,
- visible, vlinesize, voffset, vregistrationpoint, vscrollbar, watch,
- white, widget, width, window, wrap, yahooCheckLogin, yahooLogin,
- yahooLogout, zorder
- */
- /*global JSLINT*/
- // We build the application inside a function so that we produce only a single
- // global variable. The function will be invoked, its return value is the JSLINT
- // application itself.
- "use strict";
- JSLINT = function () {
- var adsafe_id, // The widget's ADsafe id.
- adsafe_may, // The widget may load approved scripts.
- adsafe_went, // ADSAFE.go has been called.
- anonname, // The guessed name for anonymous functions.
- approved, // ADsafe approved urls.
- // These are members that should not be permitted in third party ads.
- banned = { // the member names that ADsafe prohibits.
- apply : true,
- 'arguments' : true,
- call : true,
- callee : true,
- caller : true,
- constructor : true,
- 'eval' : true,
- prototype : true,
- unwatch : true,
- valueOf : true,
- watch : true
- },
- // These are the JSLint boolean options.
- boolOptions = {
- adsafe : true, // if ADsafe should be enforced
- bitwise : true, // if bitwise operators should not be allowed
- browser : true, // if the standard browser globals should be predefined
- cap : true, // if upper case HTML should be allowed
- debug : true, // if debugger statements should be allowed
- eqeqeq : true, // if === should be required
- evil : true, // if eval should be allowed
- forin : true, // if for in statements must filter
- fragment : true, // if HTML fragments should be allowed
- laxbreak : true, // if line breaks should not be checked
- nomen : true, // if names should be checked
- 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 not be allowed
- regexp : true, // if the . should not be allowed in regexp literals
- rhino : true, // if the Rhino environment globals should be predefined
- undef : true, // if variables should be declared before used
- safe : true, // if use of some browser features should be restricted
- sidebar : true, // if the System object should be predefined
- sub : true, // if all forms of subscript notation are tolerated
- white : true, // if strict whitespace rules apply
- widget : true // if the Yahoo Widgets globals should be predefined
- },
- // browser contains a set of global names which are commonly provided by a
- // web browser environment.
- browser = {
- alert : true,
- blur : true,
- clearInterval : true,
- clearTimeout : true,
- close : true,
- closed : true,
- confirm : true,
- console : true,
- Debug : true,
- defaultStatus : true,
- document : true,
- event : true,
- focus : true,
- frames : true,
- getComputedStyle: true,
- history : true,
- Image : true,
- length : true,
- location : true,
- moveBy : true,
- moveTo : true,
- name : true,
- navigator : true,
- onblur : true,
- onerror : true,
- onfocus : true,
- onload : true,
- onresize : true,
- onunload : true,
- open : true,
- opener : true,
- opera : true,
- Option : true,
- parent : true,
- print : true,
- prompt : true,
- resizeBy : true,
- resizeTo : true,
- screen : true,
- scroll : true,
- scrollBy : true,
- scrollTo : true,
- self : true,
- setInterval : true,
- setTimeout : true,
- status : true,
- top : true,
- window : true,
- XMLHttpRequest : true
- },
- escapes = {
- '\b': '\\b',
- '\t': '\\t',
- '\n': '\\n',
- '\f': '\\f',
- '\r': '\\r',
- '"' : '\\"',
- '/' : '\\/',
- '\\': '\\\\'
- },
- funct, // The current function
- functions, // All of the functions
- href = {
- background : true,
- content : true,
- data : true,
- dynsrc : true,
- href : true,
- lowsrc : true,
- src : true
- },
- global, // The global scope
- ids, // HTML ids
- implied, // Implied globals
- inblock,
- indent,
- jsonmode,
- lines,
- lookahead,
- member,
- membersOnly,
- nexttoken,
- noreach,
- option,
- predefined, // Global variables defined by option
- prereg,
- prevtoken,
- rhino = {
- defineClass : true,
- deserialize : true,
- gc : true,
- help : true,
- load : true,
- loadClass : true,
- print : true,
- quit : true,
- readFile : true,
- readUrl : true,
- runCommand : true,
- seal : true,
- serialize : true,
- spawn : true,
- sync : true,
- toint32 : true,
- version : true
- },
- scope, // The current scope
- sidebar = {
- System : true
- },
- src,
- stack,
- // standard contains the global names that are provided by the
- // ECMAScript standard.
- standard = {
- Array : true,
- Boolean : true,
- Date : true,
- decodeURI : true,
- decodeURIComponent : true,
- encodeURI : true,
- encodeURIComponent : true,
- Error : true,
- 'eval' : true,
- EvalError : true,
- Function : true,
- isFinite : true,
- isNaN : true,
- JSON : true,
- Math : true,
- Number : true,
- Object : true,
- parseInt : true,
- parseFloat : true,
- RangeError : true,
- ReferenceError : true,
- RegExp : true,
- String : true,
- SyntaxError : true,
- TypeError : true,
- URIError : true
- },
- standard_member = {
- E : true,
- LN2 : true,
- LN10 : true,
- LOG2E : true,
- LOG10E : true,
- PI : true,
- SQRT1_2 : true,
- SQRT2 : true,
- MAX_VALUE : true,
- MIN_VALUE : true,
- NEGATIVE_INFINITY : true,
- POSITIVE_INFINITY : true
- },
- syntax = {},
- tab,
- token,
- urls,
- warnings,
- // widget contains the global names which are provided to a Yahoo
- // (fna Konfabulator) widget.
- widget = {
- alert : true,
- appleScript : true,
- animator : true,
- appleScript : true,
- beep : true,
- bytesToUIString : true,
- Canvas : true,
- chooseColor : true,
- chooseFile : true,
- chooseFolder : true,
- closeWidget : true,
- COM : true,
- convertPathToHFS : true,
- convertPathToPlatform : true,
- CustomAnimation : true,
- escape : true,
- FadeAnimation : true,
- filesystem : true,
- focusWidget : true,
- form : true,
- FormField : true,
- Frame : true,
- HotKey : true,
- Image : true,
- include : true,
- isApplicationRunning : true,
- iTunes : true,
- konfabulatorVersion : true,
- log : true,
- MenuItem : true,
- MoveAnimation : true,
- openURL : true,
- play : true,
- Point : true,
- popupMenu : true,
- preferenceGroups : true,
- preferences : true,
- print : true,
- prompt : true,
- random : true,
- reloadWidget : true,
- resolvePath : true,
- resumeUpdates : true,
- RotateAnimation : true,
- runCommand : true,
- runCommandInBg : true,
- saveAs : true,
- savePreferences : true,
- screen : true,
- ScrollBar : true,
- showWidgetPreferences : true,
- sleep : true,
- speak : true,
- suppressUpdates : true,
- system : true,
- tellWidget : true,
- Text : true,
- TextArea : true,
- Timer : true,
- unescape : true,
- updateNow : true,
- URL : true,
- widget : true,
- Window : true,
- XMLDOM : true,
- XMLHttpRequest : true,
- yahooCheckLogin : true,
- yahooLogin : true,
- yahooLogout : true
- },
- // xmode is used to adapt to the exceptions in XML parsing.
- // It can have these states:
- // false .js script file
- // " A " attribute
- // ' A ' attribute
- // content The content of a script tag
- // CDATA A CDATA block
- xmode,
- // xtype identifies the type of document being analyzed.
- // It can have these states:
- // false .js script file
- // html .html file
- // widget .kon Konfabulator file
- xtype,
- // unsafe comment or string
- ax = /@cc|<\/?script|\]\]|<!|</i,
- // unsafe character
- cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
- // token
- tx = /^\s*([(){}\[.,:;'"~]|\](\]>)?|\?>?|==?=?|\/(\*(global|extern|jslint|member|members)?|=|\/)?|\*[\/=]?|\+[+=]?|-[\-=]?|%[=>]?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=%\?]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/,
- // star slash
- lx = /\*\/|\/\*/,
- // identifier
- ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/,
- // javascript url
- jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i,
- // url badness
- ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto/i;
- function F() {}
- if (typeof Object.create !== 'function') {
- Object.create = function (o) {
- F.prototype = o;
- return new F();
- };
- }
- Object.prototype.union = function (o) {
- var n;
- for (n in o) {
- if (o.hasOwnProperty(n)) {
- this[n] = o[n];
- }
- }
- };
- String.prototype.entityify = function () {
- return this.
- replace(/&/g, '&').
- replace(/</g, '<').
- replace(/>/g, '>');
- };
- String.prototype.isAlpha = function () {
- return (this >= 'a' && this <= 'z\uffff') ||
- (this >= 'A' && this <= 'Z\uffff');
- };
- String.prototype.isDigit = function () {
- return (this >= '0' && this <= '9');
- };
- String.prototype.supplant = function (o) {
- return this.replace(/\{([^{}]*)\}/g, function (a, b) {
- var r = o[b];
- return typeof r === 'string' || typeof r === 'number' ? r : a;
- });
- };
- String.prototype.name = function () {
- // If the string looks like an identifier, then we can return it as is.
- // If the string contains no control characters, no quote characters, and no
- // backslash characters, then we can simply slap some quotes around it.
- // Otherwise we must also replace the offending characters with safe
- // sequences.
- if (ix.test(this)) {
- return this;
- }
- if (/[&<"\/\\\x00-\x1f]/.test(this)) {
- return '"' + this.replace(/[&<"\/\\\x00-\x1f]/g, function (a) {
- var c = escapes[a];
- if (c) {
- return c;
- }
- c = a.charCodeAt();
- return '\\u00' +
- Math.floor(c / 16).toString(16) +
- (c % 16).toString(16);
- }) + '"';
- }
- return '"' + this + '"';
- };
- function assume() {
- if (!option.safe) {
- if (option.rhino) {
- predefined.union(rhino);
- }
- if (option.browser || option.sidebar) {
- predefined.union(browser);
- }
- if (option.sidebar) {
- predefined.union(sidebar);
- }
- if (option.widget) {
- predefined.union(widget);
- }
- }
- }
- // Produce an error warning.
- function quit(m, l, ch) {
- throw {
- name: 'JSLintError',
- line: l,
- character: ch,
- message: m + " (" + Math.floor((l / lines.length) * 100) +
- "% scanned)."
- };
- }
- function warning(m, t, a, b, c, d) {
- var ch, l, w;
- t = t || nexttoken;
- if (t.id === '(end)') {
- t = token;
- }
- l = t.line || 0;
- ch = t.from || 0;
- w = {
- id: '(error)',
- raw: m,
- evidence: lines[l] || '',
- line: l,
- character: ch,
- a: a,
- b: b,
- c: c,
- d: d
- };
- w.reason = m.supplant(w);
- JSLINT.errors.push(w);
- if (option.passfail) {
- quit('Stopping. ', l, ch);
- }
- warnings += 1;
- if (warnings === 50) {
- quit("Too many errors.", l, ch);
- }
- return w;
- }
- function warningAt(m, l, ch, a, b, c, d) {
- return warning(m, {
- line: l,
- from: ch
- }, a, b, c, d);
- }
- function error(m, t, a, b, c, d) {
- var w = warning(m, t, a, b, c, d);
- quit("Stopping, unable to continue.", w.line, w.character);
- }
- function errorAt(m, l, ch, a, b, c, d) {
- return error(m, {
- line: l,
- from: ch
- }, a, b, c, d);
- }
- // lexical analysis
- var lex = function () {
- var character, from, line, s;
- // Private lex methods
- function nextLine() {
- var at;
- line += 1;
- if (line >= lines.length) {
- return false;
- }
- character = 0;
- s = lines[line].replace(/\t/g, tab);
- at = s.search(cx);
- if (at >= 0) {
- warningAt("Unsafe character.", line, at);
- }
- return true;
- }
- // Produce a token object. The token inherits from a syntax symbol.
- function it(type, value) {
- var i, t;
- if (type === '(punctuator)' ||
- (type === '(identifier)' && syntax.hasOwnProperty(value))) {
- t = syntax[value];
- // Mozilla bug workaround.
- if (!t.id) {
- t = syntax[type];
- }
- } else {
- t = syntax[type];
- }
- t = Object.create(t);
- if (type === '(string)') {
- if (jx.test(value)) {
- warningAt("Script URL.", line, from);
- }
- } else if (type === '(identifier)') {
- if (option.nomen && (value.charAt(0) === '_' ||
- value.charAt(value.length - 1) === '_')) {
- warningAt("Unexpected '_' in '{a}'.", line, from, value);
- }
- }
- t.value = value;
- t.line = line;
- t.character = character;
- t.from = from;
- i = t.id;
- if (i !== '(endline)') {
- prereg = i &&
- (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) ||
- i === 'return');
- }
- return t;
- }
- // Public lex methods
- return {
- init: function (source) {
- if (typeof source === 'string') {
- lines = source.
- replace(/\r\n/g, '\n').
- replace(/\r/g, '\n').
- split('\n');
- } else {
- lines = source;
- }
- line = -1;
- nextLine();
- from = 0;
- },
- // token -- this is called by advance to get the next token.
- token: function () {
- var b, c, captures, d, depth, high, i, l, low, q, t;
- function match(x) {
- var r = x.exec(s), r1;
- if (r) {
- l = r[0].length;
- r1 = r[1];
- c = r1.charAt(0);
- s = s.substr(l);
- character += l;
- from = character - r1.length;
- return r1;
- }
- }
- function string(x) {
- var c, j, r = '';
- if (jsonmode && x !== '"') {
- warningAt("Strings must use doublequote.",
- line, character);
- }
- if (xmode === x || xmode === 'string') {
- if (xmode && xmode !== 'CDATA' && ax.test(x)) {
- warning("ADsafe string violation.", line, character);
- }
- return it('(punctuator)', x);
- }
- function esc(n) {
- var i = parseInt(s.substr(j + 1, n), 16);
- j += n;
- if (i >= 32 && i <= 127 &&
- i !== 34 && i !== 92 && i !== 39) {
- warningAt("Unnecessary escapement.", line, character);
- }
- character += n;
- c = String.fromCharCode(i);
- }
- j = 0;
- for (;;) {
- while (j >= s.length) {
- j = 0;
- if (xmode !== 'xml' || !nextLine()) {
- errorAt("Unclosed string.", line, from);
- }
- }
- c = s.charAt(j);
- if (c === x) {
- character += 1;
- s = s.substr(j + 1);
- return it('(string)', r, x);
- }
- if (c < ' ') {
- if (c === '\n' || c === '\r') {
- break;
- }
- warningAt("Control character in string: {a}.",
- line, character + j, s.slice(0, j));
- } else if (c === '<') {
- if (option.safe && xmode === 'xml') {
- warningAt("ADsafe string violation.",
- line, character + j);
- } else if (s.charAt(j + 1) === '/' && ((xmode && xmode !== 'CDATA') || option.safe)) {
- warningAt("Expected '<\\/' and instead saw '</'.", line, character);
- } else if (s.charAt(j + 1) === '!' && ((xmode && xmode !== 'CDATA') || option.safe)) {
- warningAt("Unexpected '<!' in a string.", line, character);
- }
- } else if (c === '\\') {
- if (option.safe && xmode === 'xml') {
- warningAt("ADsafe string violation.",
- line, character + j);
- }
- j += 1;
- character += 1;
- c = s.charAt(j);
- switch (c) {
- case '\\':
- case '\'':
- case '"':
- case '/':
- break;
- case 'b':
- c = '\b';
- break;
- case 'f':
- c = '\f';
- break;