diff --git a/lib/ace/worker/jshint.js b/lib/ace/worker/jshint.js index fba105ea..0f408db9 100644 --- a/lib/ace/worker/jshint.js +++ b/lib/ace/worker/jshint.js @@ -41,7 +41,7 @@ define(function(require, exports, module) { 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. + JavaScript text or a JSON text. The second parameter is an optional object of options which control the operation of JSHINT. Most of the options are booleans: They are all @@ -155,116 +155,60 @@ define(function(require, exports, module) { evil: true, nomen: false, onevar: false, regexp: false, strict: true, boss: true */ -/*members "\b", "\t", "\n", "\f", "\r", "!=", "!==", "\"", "%", - "(begin)", "(breakage)", "(context)", "(error)", "(global)", - "(identifier)", "(last)", "(line)", "(loopage)", "(name)", "(onevar)", - "(params)", "(scope)", "(statement)", "(verb)", "*", "+", "++", "-", - "--", "\/", "<", "<=", "==", "===", ">", ">=", $, ADSAFE, __filename, __dirname, - ActiveXObject, Array, Boolean, Buffer, COM, CScript, Canvas, CustomAnimation, - Date, Debug, E, Enumerator, Error, EvalError, FadeAnimation, Flash, - 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, Rectangle, ReferenceError, RegExp, ResizeAnimation, - RotateAnimation, SQRT1_2, SQRT2, ScrollBar, String, Style, SyntaxError, - System, Text, TextArea, Timer, TypeError, URIError, URL, VBArray, - WScript, Web, Window, XMLDOM, XMLHttpRequest, "\\", a, abbr, acronym, - activeborder, activecaption, addEventListener, address, adsafe, alert, - aliceblue, all, animator, antiquewhite, appleScript, applet, apply, - approved, appworkspace, applicationCache, aqua, aquamarine, area, arguments, - arity, article, aside, audio, autocomplete, azure, b, background, - "background-attachment", "background-color", "background-image", - "background-position", "background-repeat", base, bdo, beep, beige, big, - bisque, bitwise, black, blanchedalmond, block, blockquote, blue, - blueviolet, blur, body, border, "border-bottom", "border-bottom-color", - "border-bottom-style", "border-bottom-width", "border-collapse", - "border-color", "border-left", "border-left-color", "border-left-style", - "border-left-width", "border-right", "border-right-color", - "border-right-style", "border-right-width", "border-spacing", - "border-style", "border-top", "border-top-color", "border-top-style", - "border-top-width", "border-width", bottom, boss, br, braille, brown, browser, - burlywood, button, buttonface, buttonhighlight, buttonshadow, - buttontext, bytesToUIString, c, cadetblue, call, callee, caller, canvas, - cap, caption, "caption-side", captiontext, cases, center, charAt, - charCodeAt, character, chartreuse, chocolate, chooseColor, chooseFile, - chooseFolder, cite, clear, clearInterval, clearTimeout, clip, close, - closeWidget, closed, closure, cm, code, col, colgroup, color, command, - comment, condition, confirm, console, constructor, content, - convertPathToHFS, convertPathToPlatform, coral, cornflowerblue, - cornsilk, couch, "counter-increment", "counter-reset", create, crimson, - css, curly, cursor, cyan, d, darkblue, darkcyan, darkgoldenrod, darkgray, - darkgreen, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, - darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise, - darkviolet, data, datalist, dd, debug, decodeURI, decodeURIComponent, - deeppink, deepskyblue, defaultStatus, defineClass, del, deserialize, - details, devel, dfn, dialog, dimgray, dir, direction, display, div, dl, - document, dodgerblue, dt, edition, else, em, embed, embossed, emit, empty, - "empty-cells", encodeURI, encodeURIComponent, entityify, eqeqeq, errors, - es5, escape, eval, event, evidence, evil, ex, exception, exec, exps, exports, - fieldset, figure, filesystem, FileReader, firebrick, first, float, floor, - floralwhite, focus, focusWidget, font, "font-family", "font-size", - "font-size-adjust", "font-stretch", "font-style", "font-variant", - "font-weight", footer, forestgreen, forin, form, fragment, frame, - frames, frameset, from, fromCharCode, fuchsia, fud, funct, function, - functions, g, gainsboro, gc, getComputedStyle, getRow, ghostwhite, GLOBAL, global, - globals, gold, goldenrod, gray, graytext, green, greenyellow, h1, h2, - h3, h4, h5, h6, handheld, hasOwnProperty, head, header, height, help, - hgroup, highlight, highlighttext, history, honeydew, hotpink, hr, - "hta:application", html, i, iTunes, id, identifier, iframe, img, immed, - implieds, in, inactiveborder, inactivecaption, inactivecaptiontext, - include, indent, indexOf, indianred, indigo, infobackground, infotext, - init, input, ins, isAlpha, isApplicationRunning, isArray, isDigit, - isFinite, isNaN, ivory, join, jshint, JSHINT, json, jquery, jQuery, kbd, - keygen, keys, khaki, konfabulatorVersion, label, labelled, lang, last, - lavender, lavenderblush, lawngreen, laxbreak, lbp, led, left, legend, - lemonchiffon, length, "letter-spacing", li, lib, lightblue, lightcoral, - lightcyan, lightgoldenrodyellow, lightgreen, lightpink, lightsalmon, - lightseagreen, lightskyblue, lightslategray, lightsteelblue, - lightyellow, lime, limegreen, line, "line-height", linen, link, - "list-style", "list-style-image", "list-style-position", - "list-style-type", load, loadClass, localStorage, location, log, m, magenta, - map, margin, "margin-bottom", "margin-left", "margin-right", "margin-top", - mark, "marker-offset", maroon, match, "max-height", "max-width", maxerr, - maxlen, md5, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, - mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, - mediumvioletred, member, menu, menutext, message, meta, meter, - midnightblue, "min-height", "min-width", mintcream, mistyrose, mm, - moccasin, module, moveBy, moveTo, name, nav, navajowhite, navigator, navy, new, - newcap, noarg, node, noempty, noframes, nomen, nonew, noscript, nud, object, ol, - oldlace, olive, olivedrab, on, onbeforeunload, onblur, onerror, onevar, - onfocus, onload, onresize, onunload, opacity, open, openDatabase, openURL, opener, - opera, optgroup, option, orange, orangered, orchid, 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", - palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, - param, parent, parseFloat, parseInt, passfail, pc, peachpuff, peru, - pink, play, plum, plusplus, pop, popupMenu, position, powderblue, pre, - predef, preferenceGroups, preferences, print, process, progress, projection, - prompt, prototype, pt, purple, push, px, q, quit, quotes, random, range, - raw, reach, readFile, readUrl, reason, red, regexp, reloadWidget, - removeEventListener, replace, report, require, reserved, resizeBy, resizeTo, - resolvePath, resumeUpdates, respond, rhino, right, rosybrown, royalblue, - rp, rt, ruby, runCommand, runCommandInBg, saddlebrown, safe, salmon, samp, - sandybrown, saveAs, savePreferences, screen, script, scroll, scrollBy, - scrollTo, scrollbar, seagreen, seal, search, seashell, section, send, select, - serialize, setInterval, setTimeout, shift, showWidgetPreferences, - sienna, silver, skyblue, slateblue, slategray, sleep, slice, small, - snow, sort, source, span, spawn, speak, speech, split, springgreen, src, - stack, status, start, steelblue, strict, strong, style, styleproperty, sub, - substr, sum, sup, supplant, suppressUpdates, sync, system, table, - "table-layout", tan, tbody, td, teal, tellWidget, test, "text-align", - "text-decoration", "text-indent", "text-shadow", "text-transform", - textarea, tfoot, th, thead, thistle, threeddarkshadow, threedface, - threedhighlight, threedlightshadow, threedshadow, time, title, - toLowerCase, toString, toUpperCase, toint32, token, tomato, top, tr, tt, - tty, turquoise, tv, type, u, ul, undef, unescape, "unicode-bidi", - unused, unwatch, updateNow, urls, value, valueOf, var, version, - "vertical-align", video, violet, visibility, watch, WebSocket, wheat, white, - "white-space", whitesmoke, widget, width, window, windowframe, windows, - windowtext, Worker, "word-spacing", "word-wrap", yahooCheckLogin, - yahooLogin, yahooLogout, yellow, yellowgreen, "z-index" -*/ +/*members "\b", "\t", "\n", "\f", "\r", "!=", "!==", "\"", "%", "(begin)", + "(breakage)", "(context)", "(error)", "(global)", "(identifier)", "(last)", + "(line)", "(loopage)", "(name)", "(onevar)", "(params)", "(scope)", + "(statement)", "(verb)", "*", "+", "++", "-", "--", "\/", "<", "<=", "==", + "===", ">", ">=", $, $$, $A, $F, $H, $R, $break, $continue, $w, Abstract, Ajax, + __filename, __dirname, ActiveXObject, Array, ArrayBuffer, ArrayBufferView, + Autocompleter, Assets, Boolean, Builder, Buffer, Browser, COM, CScript, Canvas, + CustomAnimation, Class, Control, Chain, Color, Cookie, Core, DataView, Date, + Debug, Draggable, Draggables, Droppables, Document, DomReady, DOMReady, Drag, + E, Enumerator, Enumerable, Element, Elements, Error, Effect, EvalError, Event, + Events, FadeAnimation, Field, Flash, Float32Array, Float64Array, Form, + FormField, Frame, Function, Fx, GetObject, Group, Hash, HotKey, HTMLElement, + HtmlTable, Iframe, IframeShim, Image, Int16Array, Int32Array, Int8Array, + Insertion, InputValidator, JSON, Keyboard, Locale, LN10, LN2, LOG10E, LOG2E, + MAX_VALUE, MIN_VALUE, Mask, Math, MenuItem, MoveAnimation, MooTools, Native, + NEGATIVE_INFINITY, Number, Object, ObjectRange, Option, Options, OverText, PI, + POSITIVE_INFINITY, PeriodicalExecuter, Point, Position, Prototype, RangeError, + Rectangle, ReferenceError, RegExp, ResizeAnimation, Request, RotateAnimation, + SQRT1_2, SQRT2, ScrollBar, ScriptEngine, ScriptEngineBuildVersion, + ScriptEngineMajorVersion, ScriptEngineMinorVersion, Scriptaculous, Scroller, + Slick, Slider, Selector, String, Style, SyntaxError, Sortable, Sortables, + SortableObserver, Sound, Spinner, System, Swiff, Text, TextArea, Template, + Timer, Tips, Type, TypeError, Toggle, Try, URI, URIError, URL, VBArray, WSH, + WScript, Web, Window, XMLDOM, XMLHttpRequest, XPathEvaluator, XPathException, + XPathExpression, XPathNamespace, XPathNSResolver, XPathResult, "\\", a, + addEventListener, address, alert, apply, applicationCache, arguments, arity, + asi, b, bitwise, block, blur, boolOptions, boss, browser, c, call, callee, + caller, cases, charAt, charCodeAt, character, clearInterval, clearTimeout, + close, closed, closure, comment, condition, confirm, console, constructor, + content, couch, create, css, curly, d, data, datalist, dd, debug, decodeURI, + decodeURIComponent, defaultStatus, defineClass, deserialize, devel, document, + edition, else, emit, encodeURI, encodeURIComponent, entityify, eqeqeq, eqnull, + errors, es5, escape, eval, event, evidence, evil, ex, exception, exec, exps, + expr, exports, FileReader, first, floor, focus, forin, fragment, frames, from, + fromCharCode, fud, funct, function, functions, g, gc, getComputedStyle, getRow, + GLOBAL, global, globals, globalstrict, hasOwnProperty, help, history, i, id, + identifier, immed, implieds, include, indent, indexOf, init, ins, instanceOf, + isAlpha, isApplicationRunning, isArray, isDigit, isFinite, isNaN, join, jshint, + JSHINT, json, jquery, jQuery, keys, label, labelled, last, lastsemic, laxbreak, + latedef, lbp, led, left, length, line, load, loadClass, localStorage, location, + log, loopfunc, m, match, maxerr, maxlen, member,message, meta, module, moveBy, + moveTo, mootools, name, navigator, new, newcap, noarg, node, noempty, nomen, + nonew, nud, onbeforeunload, onblur, onerror, onevar, onfocus, onload, onresize, + onunload, open, openDatabase, openURL, opener, opera, outer, param, parent, + parseFloat, parseInt, passfail, plusplus, predef, print, process, prompt, + prototype, prototypejs, push, quit, range, raw, reach, reason, regexp, + readFile, readUrl, regexdash, removeEventListener, replace, report, require, + reserved, resizeBy, resizeTo, resolvePath, resumeUpdates, respond, rhino, right, + runCommand, scroll, screen, scrollBy, scrollTo, scrollbar, search, seal, send, + serialize, setInterval, setTimeout, shift, slice, sort,spawn, split, stack, + status, start, strict, sub, substr, supernew, shadow, supplant, sum, sync, + test, toLowerCase, toString, toUpperCase, toint32, token, top, trailing, type, + typeOf, Uint16Array, Uint32Array, Uint8Array, undef, unused, urls, value, valueOf, + var, version, WebSocket, white, window, Worker, wsh*/ /*global exports: false */ @@ -275,11 +219,7 @@ define(function(require, exports, module) { var JSHINT = (function () { "use strict"; - 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. + var anonname, // The guessed name for anonymous functions. // These are operators that should not be used with the ! operator. @@ -299,68 +239,59 @@ var JSHINT = (function () { '%' : true }, -// These are property names that should not be permitted in the safe subset. - - banned = { // the member names that ADsafe prohibits. - 'arguments' : true, - callee : true, - caller : true, - constructor : true, - 'eval' : true, - prototype : true, - stack : true, - unwatch : true, - valueOf : true, - watch : true - }, - - // These are the JSHint boolean options. boolOptions = { - adsafe : true, // if ADsafe should be enforced - bitwise : true, // if bitwise operators should not be allowed - boss : true, // if advanced usage of assignments and == should be allowed - browser : true, // if the standard browser globals should be predefined - cap : true, // if upper case HTML should be allowed - couch : true, // if CouchDB globals should be predefined - css : true, // if CSS workarounds should be tolerated - curly : true, // if curly braces around blocks should be required (even in if/for/while) - debug : true, // if debugger statements should be allowed - devel : true, // if logging should be allowed (console, alert, etc.) - eqeqeq : true, // if === should be required - es5 : true, // if ES5 syntax should be allowed - evil : true, // if eval should be allowed - forin : true, // if for in statements must filter - fragment : true, // if HTML fragments should be allowed - immed : true, // if immediate invocations must be wrapped in parens - jquery : true, // if jQuery globals should be predefined - laxbreak : true, // if line breaks should not be checked - newcap : true, // if constructor names must be capitalized - noarg : true, // if arguments.caller and arguments.callee should be disallowed - node : true, // if the Node.js environment globals should be predefined - noempty : true, // if empty blocks should be disallowed - nonew : true, // if using `new` for side-effects should be disallowed - nomen : true, // if names should be checked - on : true, // if HTML event handlers should be allowed - onevar : true, // if only one var statement per function 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 - windows : true, // if MS Windows-specigic globals should be predefined - strict : true, // require the "use strict"; pragma - 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 + asi : true, // if automatic semicolon insertion should be tolerated + bitwise : true, // if bitwise operators should not be allowed + boss : true, // if advanced usage of assignments should be allowed + browser : true, // if the standard browser globals should be predefined + couch : true, // if CouchDB globals should be predefined + curly : true, // if curly braces around blocks should be required (even in if/for/while) + debug : true, // if debugger statements should be allowed + devel : true, // if logging globals should be predefined (console, alert, etc.) + eqeqeq : true, // if === should be required + eqnull : true, // if == null comparisons should be tolerated + es5 : true, // if ES5 syntax should be allowed + evil : true, // if eval should be allowed + expr : true, // if ExpressionStatement should be allowed as Programs + forin : true, // if for in statements must filter + globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict') + immed : true, // if immediate invocations must be wrapped in parens + jquery : true, // if jQuery globals should be predefined + latedef : true, // if the use before definition should not be tolerated + laxbreak : true, // if line breaks should not be checked + loopfunc : true, // if functions should be allowed to be defined within loops + mootools : true, // if MooTools globals should be predefined + newcap : true, // if constructor names must be capitalized + noarg : true, // if arguments.caller and arguments.callee should be disallowed + node : true, // if the Node.js environment globals should be predefined + noempty : true, // if empty blocks should be disallowed + nonew : true, // if using `new` for side-effects should be disallowed + nomen : true, // if names should be checked + onevar : true, // if only one var statement per function should be allowed + passfail : true, // if the scan should stop on first error + plusplus : true, // if increment/decrement should not be allowed + prototypejs : true, // if Prototype and Scriptaculous globals should be predefined + regexdash : true, // if unescaped last dash (-) inside brackets should be tolerated + 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 + shadow : true, // if variable shadowing should be tolerated + strict : true, // require the "use strict"; pragma + sub : true, // if all forms of subscript notation are tolerated + supernew : true, // if `new function () { ... };` and `new Object;` should be tolerated + trailing : true, // if trailing whitespace rules apply + white : true, // if strict whitespace rules apply + wsh : true // if the Windows Scripting Host environment globals should be predefined }, // browser contains a set of global names which are commonly provided by a // web browser environment. browser = { + ArrayBuffer : false, + ArrayBufferView : false, addEventListener: false, applicationCache: false, blur : false, @@ -368,14 +299,21 @@ var JSHINT = (function () { clearTimeout : false, close : false, closed : false, + DataView : false, defaultStatus : false, document : false, event : false, FileReader : false, + Float32Array : false, + Float64Array : false, focus : false, frames : false, getComputedStyle: false, + HTMLElement : false, history : false, + Int16Array : false, + Int32Array : false, + Int8Array : false, Image : false, length : false, localStorage : false, @@ -408,10 +346,19 @@ var JSHINT = (function () { setTimeout : false, status : false, top : false, + Uint16Array : false, + Uint32Array : false, + Uint8Array : false, WebSocket : false, window : false, Worker : false, - XMLHttpRequest : false + XMLHttpRequest : false, + XPathEvaluator : false, + XPathException : false, + XPathExpression : false, + XPathNamespace : false, + XPathNSResolver : false, + XPathResult : false }, couch = { @@ -427,198 +374,6 @@ var JSHINT = (function () { module : false }, - cssAttributeData, - cssAny, - - cssColorData = { - "aliceblue" : true, - "antiquewhite" : true, - "aqua" : true, - "aquamarine" : true, - "azure" : true, - "beige" : true, - "bisque" : true, - "black" : true, - "blanchedalmond" : true, - "blue" : true, - "blueviolet" : true, - "brown" : true, - "burlywood" : true, - "cadetblue" : true, - "chartreuse" : true, - "chocolate" : true, - "coral" : true, - "cornflowerblue" : true, - "cornsilk" : true, - "crimson" : true, - "cyan" : true, - "darkblue" : true, - "darkcyan" : true, - "darkgoldenrod" : true, - "darkgray" : true, - "darkgreen" : true, - "darkkhaki" : true, - "darkmagenta" : true, - "darkolivegreen" : true, - "darkorange" : true, - "darkorchid" : true, - "darkred" : true, - "darksalmon" : true, - "darkseagreen" : true, - "darkslateblue" : true, - "darkslategray" : true, - "darkturquoise" : true, - "darkviolet" : true, - "deeppink" : true, - "deepskyblue" : true, - "dimgray" : true, - "dodgerblue" : true, - "firebrick" : true, - "floralwhite" : true, - "forestgreen" : true, - "fuchsia" : true, - "gainsboro" : true, - "ghostwhite" : true, - "gold" : true, - "goldenrod" : true, - "gray" : true, - "green" : true, - "greenyellow" : true, - "honeydew" : true, - "hotpink" : true, - "indianred" : true, - "indigo" : true, - "ivory" : true, - "khaki" : true, - "lavender" : true, - "lavenderblush" : true, - "lawngreen" : true, - "lemonchiffon" : true, - "lightblue" : true, - "lightcoral" : true, - "lightcyan" : true, - "lightgoldenrodyellow" : true, - "lightgreen" : true, - "lightpink" : true, - "lightsalmon" : true, - "lightseagreen" : true, - "lightskyblue" : true, - "lightslategray" : true, - "lightsteelblue" : true, - "lightyellow" : true, - "lime" : true, - "limegreen" : true, - "linen" : true, - "magenta" : true, - "maroon" : true, - "mediumaquamarine" : true, - "mediumblue" : true, - "mediumorchid" : true, - "mediumpurple" : true, - "mediumseagreen" : true, - "mediumslateblue" : true, - "mediumspringgreen" : true, - "mediumturquoise" : true, - "mediumvioletred" : true, - "midnightblue" : true, - "mintcream" : true, - "mistyrose" : true, - "moccasin" : true, - "navajowhite" : true, - "navy" : true, - "oldlace" : true, - "olive" : true, - "olivedrab" : true, - "orange" : true, - "orangered" : true, - "orchid" : true, - "palegoldenrod" : true, - "palegreen" : true, - "paleturquoise" : true, - "palevioletred" : true, - "papayawhip" : true, - "peachpuff" : true, - "peru" : true, - "pink" : true, - "plum" : true, - "powderblue" : true, - "purple" : true, - "red" : true, - "rosybrown" : true, - "royalblue" : true, - "saddlebrown" : true, - "salmon" : true, - "sandybrown" : true, - "seagreen" : true, - "seashell" : true, - "sienna" : true, - "silver" : true, - "skyblue" : true, - "slateblue" : true, - "slategray" : true, - "snow" : true, - "springgreen" : true, - "steelblue" : true, - "tan" : true, - "teal" : true, - "thistle" : true, - "tomato" : true, - "turquoise" : true, - "violet" : true, - "wheat" : true, - "white" : true, - "whitesmoke" : true, - "yellow" : true, - "yellowgreen" : true, - - "activeborder" : true, - "activecaption" : true, - "appworkspace" : true, - "background" : true, - "buttonface" : true, - "buttonhighlight" : true, - "buttonshadow" : true, - "buttontext" : true, - "captiontext" : true, - "graytext" : true, - "highlight" : true, - "highlighttext" : true, - "inactiveborder" : true, - "inactivecaption" : true, - "inactivecaptiontext" : true, - "infobackground" : true, - "infotext" : true, - "menu" : true, - "menutext" : true, - "scrollbar" : true, - "threeddarkshadow" : true, - "threedface" : true, - "threedhighlight" : true, - "threedlightshadow" : true, - "threedshadow" : true, - "window" : true, - "windowframe" : true, - "windowtext" : true - }, - - cssBorderStyle, - cssBreak, - - cssLengthData = { - '%': true, - 'cm': true, - 'em': true, - 'ex': true, - 'in': true, - 'mm': true, - 'pc': true, - 'pt': true, - 'px': true - }, - - cssMedia, - cssOverflow, - devel = { alert : false, confirm : false, @@ -649,125 +404,6 @@ var JSHINT = (function () { functions, // All of the functions global, // The global scope - htmltag = { - 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 implied, // Implied globals inblock, indent, @@ -782,11 +418,60 @@ var JSHINT = (function () { lookahead, member, membersOnly, + + mootools = { + '$' : false, + '$$' : false, + Assets : false, + Browser : false, + Chain : false, + Class : false, + Color : false, + Cookie : false, + Core : false, + Document : false, + DomReady : false, + DOMReady : false, + Drag : false, + Element : false, + Elements : false, + Event : false, + Events : false, + Fx : false, + Group : false, + Hash : false, + HtmlTable : false, + Iframe : false, + IframeShim : false, + InputValidator : false, + instanceOf : false, + Keyboard : false, + Locale : false, + Mask : false, + MooTools : false, + Native : false, + Options : false, + OverText : false, + Request : false, + Scroller : false, + Slick : false, + Slider : false, + Sortables : false, + Spinner : false, + Swiff : false, + Tips : false, + Type : false, + typeOf : false, + URI : false, + Window : false + }, + nexttoken, node = { __filename : false, __dirname : false, + exports : false, Buffer : false, GLOBAL : false, global : false, @@ -801,6 +486,47 @@ var JSHINT = (function () { prereg, prevtoken, + prototypejs = { + '$' : false, + '$$' : false, + '$A' : false, + '$F' : false, + '$H' : false, + '$R' : false, + '$break' : false, + '$continue' : false, + '$w' : false, + Abstract : false, + Ajax : false, + Class : false, + Enumerable : false, + Element : false, + Event : false, + Field : false, + Form : false, + Hash : false, + Insertion : false, + ObjectRange : false, + PeriodicalExecuter: false, + Position : false, + Prototype : false, + Selector : false, + Template : false, + Toggle : false, + Try : false, + Autocompleter : false, + Builder : false, + Control : false, + Draggable : false, + Draggables : false, + Droppables : false, + Effect : false, + Sortable : false, + SortableObserver : false, + Sound : false, + Scriptaculous : false + }, + rhino = { defineClass : false, deserialize : false, @@ -880,109 +606,19 @@ var JSHINT = (function () { urls, warnings, -// widget contains the global names which are provided to a Yahoo -// (fna Konfabulator) widget. - - widget = { - alert : 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, - Flash : true, - focusWidget : true, - form : true, - FormField : true, - Frame : true, - HotKey : true, - Image : true, - include : true, - isApplicationRunning : true, - iTunes : true, - konfabulatorVersion : true, - log : true, - md5 : true, - MenuItem : true, - MoveAnimation : true, - openURL : true, - play : true, - Point : true, - popupMenu : true, - preferenceGroups : true, - preferences : true, - print : true, - prompt : true, - random : true, - Rectangle : true, - reloadWidget : true, - ResizeAnimation : 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, - Style : true, - suppressUpdates : true, - system : true, - tellWidget : true, - Text : true, - TextArea : true, - Timer : true, - unescape : true, - updateNow : true, - URL : true, - Web : true, - widget : true, - Window : true, - XMLDOM : true, - XMLHttpRequest : true, - yahooCheckLogin : true, - yahooLogin : true, - yahooLogout : true + wsh = { + ActiveXObject : true, + Enumerator : true, + GetObject : true, + ScriptEngine : true, + ScriptEngineBuildVersion : true, + ScriptEngineMajorVersion : true, + ScriptEngineMinorVersion : true, + VBArray : true, + WSH : true, + WScript : true }, - windows = { - ActiveXObject: false, - CScript : false, - Debug : false, - Enumerator : false, - System : false, - VBArray : false, - WScript : false - }, - -// xmode is used to adapt to the exceptions in html parsing. -// It can have these states: -// false .js script file -// html -// outer -// script -// style -// scriptstring -// styleproperty - - xmode, - xquote, - // Regular expressions. Some of these are stupidly long. // unsafe comment or string @@ -990,37 +626,18 @@ var JSHINT = (function () { // 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]/, // token - tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jshint|members?|global)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/, -// html token - hx = /^\s*(['"=>\/]|<(?:\/|\!(?:--)?)?|[a-zA-Z][a-zA-Z0-9_\-:]*|[0-9]+|--)/, + tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(jshint|jslint|members?|global)?|=|\/)?|\*[\/=]?|\+(?:=|\++)?|-(?:=|-+)?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=!]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/, // 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]/, nxg = /[\u0000-\u001f&<"\/\\\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, -// outer html token - ox = /[>&]|<[\/!]?|--/, // 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, -// style - sx = /^\s*([{:#%.=,>+\[\]@()"';]|\*=?|\$=|\|=|\^=|~=|[a-zA-Z_][a-zA-Z0-9_\-]*|[0-9]+|<\/|\/\*)/, - ssx = /^\s*([@#!"'};:\-%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\/\*?|\d+(?:\.\d+)?|<\/)/, -// attributes characters - qx = /[^a-zA-Z0-9+\-_\/ ]/, -// query characters for ids - dx = /[\[\]\/\\"'*<>.&:(){}+=#]/, - - rx = { - outer: hx, - html: hx, - style: sx, - styleproperty: ssx - }; - +// catches /* falls through */ comments + ft = /^\s*\/\*\s*falls\sthrough\s*\*\/\s*$/; function F() {} // Used by Object.create @@ -1128,15 +745,15 @@ var JSHINT = (function () { } function assume() { - if (option.safe) - return; - if (option.couch) combine(predefined, couch); if (option.rhino) combine(predefined, rhino); + if (option.prototypejs) + combine(predefined, prototypejs); + if (option.node) combine(predefined, node); @@ -1149,23 +766,27 @@ var JSHINT = (function () { if (option.jquery) combine(predefined, jquery); - if (option.windows) - combine(predefined, windows); + if (option.mootools) + combine(predefined, mootools); - if (option.widget) - combine(predefined, widget); + if (option.wsh) + combine(predefined, wsh); + + if (option.globalstrict && option.strict !== false) + option.strict = true; } // Produce an error warning. - function quit(m, l, ch) { + function quit(message, line, chr) { + var percentage = Math.floor((line / lines.length) * 100); + throw { name: 'JSHintError', - line: l, - character: ch, - message: m + " (" + Math.floor((l / lines.length) * 100) + - "% scanned)." + line: line, + character: chr, + message: message + " (" + percentage + "% scanned)." }; } @@ -1229,25 +850,34 @@ var JSHINT = (function () { // Private lex methods function nextLine() { - var at; - if (line >= lines.length) { + var at, + tw; // trailing whitespace check + + if (line >= lines.length) return false; - } + character = 1; s = lines[line]; line += 1; at = s.search(/ \t/); - if (at >= 0) { + + if (at >= 0) warningAt("Mixed spaces and tabs.", line, at + 1); - } + s = s.replace(/\t/g, tab); at = s.search(cx); - if (at >= 0) { + + if (at >= 0) warningAt("Unsafe character.", line, at); - } - if (option.maxlen && option.maxlen < s.length) { + + if (option.maxlen && option.maxlen < s.length) warningAt("Line too long.", line, s.length); - } + + // Check for trailing whitespaces + tw = s.search(/\s+$/); + if (option.trailing && ~tw) + warningAt("Trailing whitespace.", line, tw); + return true; } @@ -1306,6 +936,12 @@ var JSHINT = (function () { } else { lines = source; } + + // If the first line is a shebang (#!), make it a blank and move on. + // Shebangs are used by Node scripts. + if (lines[0] && lines[0].substr(0, 2) == '#!') + lines[0] = ''; + line = 0; nextLine(); from = 1; @@ -1330,7 +966,6 @@ var JSHINT = (function () { s = s.slice(1); character += 1; return it('(range)', value); - case xquote: case '\\': warningAt("Unexpected '{a}'.", line, character, c); } @@ -1365,10 +1000,6 @@ var JSHINT = (function () { line, character); } - if (xquote === x || (xmode === 'scriptstring' && !xquote)) { - return it('(punctuator)', x); - } - function esc(n) { var i = parseInt(s.substr(j + 1, n), 16); j += n; @@ -1383,7 +1014,7 @@ var JSHINT = (function () { for (;;) { while (j >= s.length) { j = 0; - if (xmode !== 'html' || !nextLine()) { + if (!nextLine()) { errorAt("Unclosed string.", line, from); } } @@ -1399,82 +1030,52 @@ var JSHINT = (function () { } warningAt("Control character in string: {a}.", line, character + j, s.slice(0, j)); - } else if (c === xquote) { - warningAt("Bad HTML string", line, character + j); - } else if (c === '<') { - if (option.safe && xmode === 'html') { - warningAt("ADsafe string violation.", - line, character + j); - } else if (s.charAt(j + 1) === '/' && (xmode || option.safe)) { - warningAt("Expected '<\\/' and instead saw ''.", line, character); - } else if (s.charAt(j + 1) === '!' && (xmode || option.safe)) { - warningAt("Unexpected ' 0) { - character += 1; - s = s.slice(i); - break; - } else { - if (!nextLine()) { - return it('(end)', ''); - } - } - } - t = match(rx[xmode] || tx); + t = match(tx); if (!t) { t = ''; c = ''; @@ -1509,12 +1096,7 @@ var JSHINT = (function () { s = s.substr(1); } if (s) { - if (xmode === 'html') { - return it('(error)', s.charAt(0)); - } else { - errorAt("Unexpected '{a}'.", - line, character, s.substr(0, 1)); - } + errorAt("Unexpected '{a}'.", line, character, s.substr(0, 1)); } } else { @@ -1527,20 +1109,18 @@ var JSHINT = (function () { // number if (c.isDigit()) { - if (xmode !== 'style' && !isFinite(Number(t))) { + if (!isFinite(Number(t))) { warningAt("Bad number '{a}'.", line, character, t); } - if (xmode !== 'style' && - xmode !== 'styleproperty' && - s.substr(0, 1).isAlpha()) { + if (s.substr(0, 1).isAlpha()) { warningAt("Missing space after '{a}'.", line, character, t); } if (c === '0') { d = t.substr(1, 1); if (d.isDigit()) { - if (token.id !== '.' && xmode !== 'styleproperty') { + if (token.id !== '.') { warningAt("Don't use extra leading zeros '{a}'.", line, character, t); } @@ -1566,12 +1146,8 @@ var JSHINT = (function () { // // comment case '//': - if (src || (xmode && xmode !== 'script')) { + if (src) { warningAt("Unexpected comment.", line, character); - } else if (xmode === 'script' && /<\s*\//i.test(s)) { - warningAt("Unexpected <\/ in comment.", line, character); - } else if ((option.safe || xmode === 'script') && ax.test(s)) { - warningAt("Dangerous comment.", line, character); } s = ''; token.comment = true; @@ -1580,12 +1156,9 @@ var JSHINT = (function () { // /* comment case '/*': - if (src || (xmode && xmode !== 'script' && xmode !== 'style' && xmode !== 'styleproperty')) { + if (src) { warningAt("Unexpected comment.", line, character); } - if (option.safe && ax.test(s)) { - warningAt("ADsafe comment violation.", line, character); - } for (;;) { i = s.search(lx); if (i >= 0) { @@ -1593,11 +1166,6 @@ var JSHINT = (function () { } if (!nextLine()) { errorAt("Unclosed comment.", line, character); - } else { - if (option.safe && ax.test(s)) { - warningAt("ADsafe comment violation.", - line, character); - } } } character += i + 2; @@ -1613,6 +1181,7 @@ var JSHINT = (function () { case '/*members': case '/*member': case '/*jshint': + case '/*jslint': case '/*global': case '*/': return { @@ -1757,7 +1326,7 @@ klass: do { } break; case ']': - if (!q) { + if (!q && !option.regexdash) { warningAt("Unescaped '{a}'.", line, from + l - 1, '-'); } @@ -1780,13 +1349,6 @@ klass: do { q = true; break; case '<': - if (xmode === 'script') { - c = s.charAt(l); - if (c === '!' || c === '/') { - warningAt( -"HTML confusion in regular expression '<{a}'.", line, from + l, c); - } - } q = true; break; default: @@ -1808,15 +1370,6 @@ klass: do { case '*': warningAt("Unescaped '{a}'.", line, from + l, c); - break; - case '<': - if (xmode === 'script') { - c = s.charAt(l); - if (c === '!' || c === '/') { - warningAt( -"HTML confusion in regular expression '<{a}'.", line, from + l, c); - } - } } if (b) { switch (s.charAt(l)) { @@ -1888,75 +1441,9 @@ klass: do { // punctuator - case '.", line, character); - } - character += 3; - s = s.slice(i + 3); - break; case '#': - if (xmode === 'html' || xmode === 'styleproperty') { - for (;;) { - c = s.charAt(0); - if ((c < '0' || c > '9') && - (c < 'a' || c > 'f') && - (c < 'A' || c > 'F')) { - break; - } - character += 1; - s = s.substr(1); - t += c; - } - if (t.length !== 4 && t.length !== 7) { - warningAt("Bad hex color '{a}'.", line, - from + l, t); - } - return it('(color)', t); - } return it('(punctuator)', t); default: - if (xmode === 'outer' && c === '&') { - character += 1; - s = s.substr(1); - for (;;) { - c = s.charAt(0); - character += 1; - s = s.substr(1); - if (c === ';') { - break; - } - if (!((c >= '0' && c <= '9') || - (c >= 'a' && c <= 'z') || - c === '#')) { - errorAt("Bad entity", line, from + l, - character); - } - } - break; - } return it('(punctuator)', t); } } @@ -1968,26 +1455,28 @@ klass: do { function addlabel(t, type) { - if (option.safe && funct['(global)'] && - typeof predefined[t] !== 'boolean') { - warning('ADsafe global: ' + t + '.', token); - } else if (t === 'hasOwnProperty') { + if (t === 'hasOwnProperty') { warning("'hasOwnProperty' is a really bad name."); } // Define t in the current function in the current scope. if (is_own(funct, t) && !funct['(global)']) { - warning(funct[t] === true ? - "'{a}' was used before it was defined." : - "'{a}' is already defined.", - nexttoken, t); + if (funct[t] === true) { + if (option.latedef) + warning("'{a}' was used before it was defined.", nexttoken, t); + } else { + if (!option.shadow) + warning("'{a}' is already defined.", nexttoken, t); + } } + funct[t] = type; if (funct['(global)']) { global[t] = funct; if (is_own(implied, t)) { - warning("'{a}' was used before it was defined.", nexttoken, t); + if (option.latedef) + warning("'{a}' was used before it was defined.", nexttoken, t); delete implied[t]; } } else { @@ -2011,16 +1500,11 @@ klass: do { obj = membersOnly; break; case '/*jshint': - if (option.safe) { - warning("ADsafe restriction."); - } + case '/*jslint': obj = option; filter = boolOptions; break; case '/*global': - if (option.safe) { - warning("ADsafe restriction."); - } obj = predefined; break; default: @@ -2048,7 +1532,7 @@ loop: for (;;) { error("Expected '{a}' and instead saw '{b}'.", t, '*/', ':'); } - if (t.value === 'indent' && o === '/*jshint') { + if (t.value === 'indent' && (o === '/*jshint' || o === '/*jslint')) { b = +v.value; if (typeof b !== 'number' || !isFinite(b) || b <= 0 || Math.floor(b) !== b) { @@ -2057,7 +1541,7 @@ loop: for (;;) { } obj.white = true; obj.indent = b; - } else if (t.value === 'maxerr' && o === '/*jshint') { + } else if (t.value === 'maxerr' && (o === '/*jshint' || o === '/*jslint')) { b = +v.value; if (typeof b !== 'number' || !isFinite(b) || b <= 0 || Math.floor(b) !== b) { @@ -2065,7 +1549,7 @@ loop: for (;;) { v, v.value); } obj.maxerr = b; - } else if (t.value === 'maxlen' && o === '/*jshint') { + } else if (t.value === 'maxlen' && (o === '/*jshint' || o === '/*jslint')) { b = +v.value; if (typeof b !== 'number' || !isFinite(b) || b <= 0 || Math.floor(b) !== b) { @@ -2082,7 +1566,7 @@ loop: for (;;) { } t = lex.token(); } else { - if (o === '/*jshint') { + if (o === '/*jshint' || o === '/*jslint') { error("Missing option value.", t); } obj[t.value] = false; @@ -2122,8 +1606,7 @@ loop: for (;;) { switch (token.id) { case '(number)': if (nexttoken.id === '.') { - warning( -"A dot following a number can be confused with a decimal point.", token); + warning("A dot following a number can be confused with a decimal point.", token); } break; case '-': @@ -2146,8 +1629,7 @@ loop: for (;;) { if (nexttoken.id === '(end)') { warning("Unmatched '{a}'.", t, t.id); } else { - warning( -"Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.", + warning("Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.", nexttoken, id, t.id, t.line, nexttoken.value); } } else if (nexttoken.type !== '(identifier)' || @@ -2189,15 +1671,12 @@ loop: for (;;) { // They are elements of the parsing method called Top Down Operator Precedence. function expression(rbp, initial) { - var left; - if (nexttoken.id === '(end)') { + var left, isArray = false; + + if (nexttoken.id === '(end)') error("Unexpected early end of program.", token); - } + advance(); - if (option.safe && typeof predefined[token.value] === 'boolean' && - (nexttoken.id !== '(' && nexttoken.id !== '.')) { - warning('ADsafe violation.', token); - } if (initial) { anonname = 'anonymous'; funct['(verb)'] = token.value; @@ -2209,8 +1688,7 @@ loop: for (;;) { left = token.nud(); } else { if (nexttoken.type === '(number)' && token.id === '.') { - warning( -"A leading decimal point can be confused with a dot: '.{a}'.", + warning("A leading decimal point can be confused with a dot: '.{a}'.", token, nexttoken.value); advance(); return token; @@ -2220,7 +1698,10 @@ loop: for (;;) { } } while (rbp < nexttoken.lbp) { + isArray = token.value == 'Array'; advance(); + if (isArray && token.id == '(' && nexttoken.id == ')') + warning("Use the array literal notation [].", token); if (token.led) { left = token.led(left); } else { @@ -2238,7 +1719,7 @@ loop: for (;;) { function adjacent(left, right) { left = left || token; right = right || nexttoken; - if (option.white || xmode === 'styleproperty' || xmode === 'style') { + if (option.white) { if (left.character !== right.from && left.line === right.line) { warning("Unexpected space after '{a}'.", right, left.value); } @@ -2461,7 +1942,7 @@ loop: for (;;) { return node && ((node.type === '(number)' && +node.value === 0) || (node.type === '(string)' && node.value === '') || - (node.type === 'null' && !option.boss) || + (node.type === 'null' && !option.eqnull) || node.type === 'true' || node.type === 'false' || node.type === 'undefined'); @@ -2479,15 +1960,6 @@ loop: for (;;) { } else if (left['function']) { warning("'{a}' is a function.", left, left.value); } - if (option.safe) { - l = left; - do { - if (typeof predefined[l.value] === 'boolean') { - warning('ADsafe violation.', l); - } - l = l.left; - } while (l); - } if (left) { if (left.id === '.' || left.id === '[') { if (!left.left || left.left.value === 'arguments') { @@ -2575,9 +2047,7 @@ loop: for (;;) { function optionalidentifier(fnparam) { if (nexttoken.identifier) { advance(); - if (option.safe && banned[token.value]) { - warning("ADsafe violation: '{a}'.", token, token.value); - } else if (token.reserved && !option.es5) { + if (token.reserved && !option.es5) { // `undefined` as a function param is a common pattern to protect // against the case when somebody does `undefined = true` and // help with minification. More info: https://gist.github.com/315916 @@ -2598,7 +2068,7 @@ loop: for (;;) { return i; } if (token.id === 'function' && nexttoken.id === '(') { - warning("Missing name in function statement."); + warning("Missing name in function declaration."); } else { error("Expected an identifier and instead saw '{a}'.", nexttoken, nexttoken.value); @@ -2670,13 +2140,15 @@ loop: for (;;) { // Look for the final semicolon. if (!t.block) { - if (!r || !r.exps) { + if (!option.expr && (!r || !r.exps)) { warning("Expected an assignment or function call and instead saw an expression.", token); } else if (option.nonew && r.id === '(' && r.left.id === 'new') { warning("Do not use 'new' for side effects."); } if (nexttoken.id !== ';') { - warningAt("Missing semicolon.", token.line, token.from + token.value.length); + if (!option.asi && !(option.lastsemic && nexttoken.id == '}' && nexttoken.line == token.line)) { + warningAt("Missing semicolon.", token.line, token.from + token.value.length); + } } else { adjacent(token, nexttoken); advance(';'); @@ -2711,66 +2183,7 @@ loop: for (;;) { function statements(begin) { var a = [], f, p; - if (option.adsafe) { - switch (begin) { - case 'script': -// JSHint is also the static analizer for ADsafe. See www.ADsafe.org. - - if (!adsafe_may) { - if (nexttoken.value !== 'ADSAFE' || - peek(0).id !== '.' || - (peek(1).value !== 'id' && - peek(1).value !== 'go')) { - error('ADsafe violation: Missing ADSAFE.id or ADSAFE.go.', - nexttoken); - } - } - if (nexttoken.value === 'ADSAFE' && - peek(0).id === '.' && - peek(1).value === 'id') { - if (adsafe_may) { - error('ADsafe violation.', nexttoken); - } - advance('ADSAFE'); - advance('.'); - advance('id'); - advance('('); - if (nexttoken.value !== adsafe_id) { - error('ADsafe violation: id does not match.', nexttoken); - } - advance('(string)'); - advance(')'); - advance(';'); - adsafe_may = true; - } - break; - case 'lib': - if (nexttoken.value === 'ADSAFE') { - advance('ADSAFE'); - advance('.'); - advance('lib'); - advance('('); - advance('(string)'); - comma(); - f = expression(0); - if (f.id !== 'function') { - error('The second argument to lib must be a function.', f); - } - p = f.funct['(params)']; - p = p && p.join(', '); - if (p && p !== 'lib') { - error("Expected '{a}' and instead saw '{b}'.", - f, '(lib)', '(' + p + ')'); - } - advance(')'); - advance(';'); - return a; - } else { - error("ADsafe lib violation."); - } - } - } while (!nexttoken.reach && nexttoken.id !== '(end)') { if (nexttoken.id === ';') { warning("Unnecessary semicolon."); @@ -2868,1300 +2281,6 @@ loop: for (;;) { } } - -// CSS parsing. - - function cssName() { - if (nexttoken.identifier) { - advance(); - return true; - } - } - - - function cssNumber() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - nolinebreak(); - } - if (nexttoken.type === '(number)') { - advance('(number)'); - return true; - } - } - - - function cssString() { - if (nexttoken.type === '(string)') { - advance(); - return true; - } - } - - - function cssColor() { - var i, number, value; - if (nexttoken.identifier) { - value = nexttoken.value; - if (value === 'rgb' || value === 'rgba') { - advance(); - advance('('); - for (i = 0; i < 3; i += 1) { - if (i) { - advance(','); - } - number = nexttoken.value; - if (nexttoken.type !== '(number)' || number < 0) { - warning("Expected a positive number and instead saw '{a}'", - nexttoken, number); - advance(); - } else { - advance(); - if (nexttoken.id === '%') { - advance('%'); - if (number > 100) { - warning("Expected a percentage and instead saw '{a}'", - token, number); - } - } else { - if (number > 255) { - warning("Expected a small number and instead saw '{a}'", - token, number); - } - } - } - } - if (value === 'rgba') { - advance(','); - number = +nexttoken.value; - if (nexttoken.type !== '(number)' || number < 0 || number > 1) { - warning("Expected a number between 0 and 1 and instead saw '{a}'", - nexttoken, number); - } - advance(); - if (nexttoken.id === '%') { - warning("Unexpected '%'."); - advance('%'); - } - } - advance(')'); - return true; - } else if (cssColorData[nexttoken.value] === true) { - advance(); - return true; - } - } else if (nexttoken.type === '(color)') { - advance(); - return true; - } - return false; - } - - - function cssLength() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - nolinebreak(); - } - if (nexttoken.type === '(number)') { - advance(); - if (nexttoken.type !== '(string)' && - cssLengthData[nexttoken.value] === true) { - adjacent(); - advance(); - } else if (+token.value !== 0) { - warning("Expected a linear unit and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - return true; - } - return false; - } - - - function cssLineHeight() { - if (nexttoken.id === '-') { - advance('-'); - adjacent(); - } - if (nexttoken.type === '(number)') { - advance(); - if (nexttoken.type !== '(string)' && - cssLengthData[nexttoken.value] === true) { - adjacent(); - advance(); - } - return true; - } - return false; - } - - - function cssWidth() { - if (nexttoken.identifier) { - switch (nexttoken.value) { - case 'thin': - case 'medium': - case 'thick': - advance(); - return true; - } - } else { - return cssLength(); - } - } - - - function cssMargin() { - if (nexttoken.identifier) { - if (nexttoken.value === 'auto') { - advance(); - return true; - } - } else { - return cssLength(); - } - } - - function cssAttr() { - if (nexttoken.identifier && nexttoken.value === 'attr') { - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - advance(')'); - return true; - } - return false; - } - - - function cssCommaList() { - while (nexttoken.id !== ';') { - if (!cssName() && !cssString()) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - if (nexttoken.id !== ',') { - return true; - } - comma(); - } - } - - - function cssCounter() { - if (nexttoken.identifier && nexttoken.value === 'counter') { - advance(); - advance('('); - advance(); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(')'); - return true; - } - if (nexttoken.identifier && nexttoken.value === 'counters') { - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a name and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - if (nexttoken.id === ',') { - comma(); - if (nexttoken.type !== '(string)') { - warning("Expected a string and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(')'); - return true; - } - return false; - } - - - function cssShape() { - var i; - if (nexttoken.identifier && nexttoken.value === 'rect') { - advance(); - advance('('); - for (i = 0; i < 4; i += 1) { - if (!cssLength()) { - warning("Expected a number and instead saw '{a}'.", - nexttoken, nexttoken.value); - break; - } - } - advance(')'); - return true; - } - return false; - } - - - function cssUrl() { - var c, url; - if (nexttoken.identifier && nexttoken.value === 'url') { - nexttoken = lex.range('(', ')'); - url = nexttoken.value; - c = url.charAt(0); - if (c === '"' || c === '\'') { - if (url.slice(-1) !== c) { - warning("Bad url string."); - } else { - url = url.slice(1, -1); - if (url.indexOf(c) >= 0) { - warning("Bad url string."); - } - } - } - if (!url) { - warning("Missing url."); - } - advance(); - if (option.safe && ux.test(url)) { - error("ADsafe URL violation."); - } - urls.push(url); - return true; - } - return false; - } - - - cssAny = [cssUrl, function () { - for (;;) { - if (nexttoken.identifier) { - switch (nexttoken.value.toLowerCase()) { - case 'url': - cssUrl(); - break; - case 'expression': - warning("Unexpected expression '{a}'.", - nexttoken, nexttoken.value); - advance(); - break; - default: - advance(); - } - } else { - if (nexttoken.id === ';' || nexttoken.id === '!' || - nexttoken.id === '(end)' || nexttoken.id === '}') { - return true; - } - advance(); - } - } - }]; - - - cssBorderStyle = [ - 'none', 'dashed', 'dotted', 'double', 'groove', - 'hidden', 'inset', 'outset', 'ridge', 'solid' - ]; - - cssBreak = [ - 'auto', 'always', 'avoid', 'left', 'right' - ]; - - cssMedia = { - 'all': true, - 'braille': true, - 'embossed': true, - 'handheld': true, - 'print': true, - 'projection': true, - 'screen': true, - 'speech': true, - 'tty': true, - 'tv': true - }; - - cssOverflow = [ - 'auto', 'hidden', 'scroll', 'visible' - ]; - - cssAttributeData = { - background: [ - true, 'background-attachment', 'background-color', - 'background-image', 'background-position', 'background-repeat' - ], - 'background-attachment': ['scroll', 'fixed'], - 'background-color': ['transparent', cssColor], - 'background-image': ['none', cssUrl], - 'background-position': [ - 2, [cssLength, 'top', 'bottom', 'left', 'right', 'center'] - ], - 'background-repeat': [ - 'repeat', 'repeat-x', 'repeat-y', 'no-repeat' - ], - 'border': [true, 'border-color', 'border-style', 'border-width'], - 'border-bottom': [ - true, 'border-bottom-color', 'border-bottom-style', - 'border-bottom-width' - ], - 'border-bottom-color': cssColor, - 'border-bottom-style': cssBorderStyle, - 'border-bottom-width': cssWidth, - 'border-collapse': ['collapse', 'separate'], - 'border-color': ['transparent', 4, cssColor], - 'border-left': [ - true, 'border-left-color', 'border-left-style', 'border-left-width' - ], - 'border-left-color': cssColor, - 'border-left-style': cssBorderStyle, - 'border-left-width': cssWidth, - 'border-right': [ - true, 'border-right-color', 'border-right-style', - 'border-right-width' - ], - 'border-right-color': cssColor, - 'border-right-style': cssBorderStyle, - 'border-right-width': cssWidth, - 'border-spacing': [2, cssLength], - 'border-style': [4, cssBorderStyle], - 'border-top': [ - true, 'border-top-color', 'border-top-style', 'border-top-width' - ], - 'border-top-color': cssColor, - 'border-top-style': cssBorderStyle, - 'border-top-width': cssWidth, - 'border-width': [4, cssWidth], - bottom: [cssLength, 'auto'], - 'caption-side' : ['bottom', 'left', 'right', 'top'], - clear: ['both', 'left', 'none', 'right'], - clip: [cssShape, 'auto'], - color: cssColor, - content: [ - 'open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', - cssString, cssUrl, cssCounter, cssAttr - ], - 'counter-increment': [ - cssName, 'none' - ], - 'counter-reset': [ - cssName, 'none' - ], - cursor: [ - cssUrl, 'auto', 'crosshair', 'default', 'e-resize', 'help', 'move', - 'n-resize', 'ne-resize', 'nw-resize', 'pointer', 's-resize', - 'se-resize', 'sw-resize', 'w-resize', 'text', 'wait' - ], - direction: ['ltr', 'rtl'], - display: [ - 'block', 'compact', 'inline', 'inline-block', 'inline-table', - 'list-item', 'marker', 'none', 'run-in', 'table', 'table-caption', - 'table-cell', 'table-column', 'table-column-group', - 'table-footer-group', 'table-header-group', 'table-row', - 'table-row-group' - ], - 'empty-cells': ['show', 'hide'], - 'float': ['left', 'none', 'right'], - font: [ - 'caption', 'icon', 'menu', 'message-box', 'small-caption', - 'status-bar', true, 'font-size', 'font-style', 'font-weight', - 'font-family' - ], - 'font-family': cssCommaList, - 'font-size': [ - 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', - 'xx-large', 'larger', 'smaller', cssLength - ], - 'font-size-adjust': ['none', cssNumber], - 'font-stretch': [ - 'normal', 'wider', 'narrower', 'ultra-condensed', - 'extra-condensed', 'condensed', 'semi-condensed', - 'semi-expanded', 'expanded', 'extra-expanded' - ], - 'font-style': [ - 'normal', 'italic', 'oblique' - ], - 'font-variant': [ - 'normal', 'small-caps' - ], - 'font-weight': [ - 'normal', 'bold', 'bolder', 'lighter', cssNumber - ], - height: [cssLength, 'auto'], - left: [cssLength, 'auto'], - 'letter-spacing': ['normal', cssLength], - 'line-height': ['normal', cssLineHeight], - 'list-style': [ - true, 'list-style-image', 'list-style-position', 'list-style-type' - ], - 'list-style-image': ['none', cssUrl], - 'list-style-position': ['inside', 'outside'], - 'list-style-type': [ - 'circle', 'disc', 'square', 'decimal', 'decimal-leading-zero', - 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha', - 'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'katakana', - 'hiragana-iroha', 'katakana-oroha', 'none' - ], - margin: [4, cssMargin], - 'margin-bottom': cssMargin, - 'margin-left': cssMargin, - 'margin-right': cssMargin, - 'margin-top': cssMargin, - 'marker-offset': [cssLength, 'auto'], - 'max-height': [cssLength, 'none'], - 'max-width': [cssLength, 'none'], - 'min-height': cssLength, - 'min-width': cssLength, - opacity: cssNumber, - outline: [true, 'outline-color', 'outline-style', 'outline-width'], - 'outline-color': ['invert', cssColor], - 'outline-style': [ - 'dashed', 'dotted', 'double', 'groove', 'inset', 'none', - 'outset', 'ridge', 'solid' - ], - 'outline-width': cssWidth, - overflow: cssOverflow, - 'overflow-x': cssOverflow, - 'overflow-y': cssOverflow, - padding: [4, cssLength], - 'padding-bottom': cssLength, - 'padding-left': cssLength, - 'padding-right': cssLength, - 'padding-top': cssLength, - 'page-break-after': cssBreak, - 'page-break-before': cssBreak, - position: ['absolute', 'fixed', 'relative', 'static'], - quotes: [8, cssString], - right: [cssLength, 'auto'], - 'table-layout': ['auto', 'fixed'], - 'text-align': ['center', 'justify', 'left', 'right'], - 'text-decoration': [ - 'none', 'underline', 'overline', 'line-through', 'blink' - ], - 'text-indent': cssLength, - 'text-shadow': ['none', 4, [cssColor, cssLength]], - 'text-transform': ['capitalize', 'uppercase', 'lowercase', 'none'], - top: [cssLength, 'auto'], - 'unicode-bidi': ['normal', 'embed', 'bidi-override'], - 'vertical-align': [ - 'baseline', 'bottom', 'sub', 'super', 'top', 'text-top', 'middle', - 'text-bottom', cssLength - ], - visibility: ['visible', 'hidden', 'collapse'], - 'white-space': [ - 'normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap', 'inherit' - ], - width: [cssLength, 'auto'], - 'word-spacing': ['normal', cssLength], - 'word-wrap': ['break-word', 'normal'], - 'z-index': ['auto', cssNumber] - }; - - function styleAttribute() { - var v; - while (nexttoken.id === '*' || nexttoken.id === '#' || - nexttoken.value === '_') { - if (!option.css) { - warning("Unexpected '{a}'.", nexttoken, nexttoken.value); - } - advance(); - } - if (nexttoken.id === '-') { - if (!option.css) { - warning("Unexpected '{a}'.", nexttoken, nexttoken.value); - } - advance('-'); - if (!nexttoken.identifier) { - warning( -"Expected a non-standard style attribute and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - advance(); - return cssAny; - } else { - if (!nexttoken.identifier) { - warning("Excepted a style attribute, and instead saw '{a}'.", - nexttoken, nexttoken.value); - } else { - if (is_own(cssAttributeData, nexttoken.value)) { - v = cssAttributeData[nexttoken.value]; - } else { - v = cssAny; - if (!option.css) { - warning("Unrecognized style attribute '{a}'.", - nexttoken, nexttoken.value); - } - } - } - advance(); - return v; - } - } - - - function styleValue(v) { - var i = 0, - n, - once, - match, - round, - start = 0, - vi; - switch (typeof v) { - case 'function': - return v(); - case 'string': - if (nexttoken.identifier && nexttoken.value === v) { - advance(); - return true; - } - return false; - } - for (;;) { - if (i >= v.length) { - return false; - } - vi = v[i]; - i += 1; - if (vi === true) { - break; - } else if (typeof vi === 'number') { - n = vi; - vi = v[i]; - i += 1; - } else { - n = 1; - } - match = false; - while (n > 0) { - if (styleValue(vi)) { - match = true; - n -= 1; - } else { - break; - } - } - if (match) { - return true; - } - } - start = i; - once = []; - for (;;) { - round = false; - for (i = start; i < v.length; i += 1) { - if (!once[i]) { - if (styleValue(cssAttributeData[v[i]])) { - match = true; - round = true; - once[i] = true; - break; - } - } - } - if (!round) { - return match; - } - } - } - - function styleChild() { - if (nexttoken.id === '(number)') { - advance(); - if (nexttoken.value === 'n' && nexttoken.identifier) { - adjacent(); - advance(); - if (nexttoken.id === '+') { - adjacent(); - advance('+'); - adjacent(); - advance('(number)'); - } - } - return; - } else { - switch (nexttoken.value) { - case 'odd': - case 'even': - if (nexttoken.identifier) { - advance(); - return; - } - } - } - warning("Unexpected token '{a}'.", nexttoken, nexttoken.value); - } - - function substyle() { - var v; - for (;;) { - if (nexttoken.id === '}' || nexttoken.id === '(end)' || - xquote && nexttoken.id === xquote) { - return; - } - while (nexttoken.id === ';') { - warning("Misplaced ';'."); - advance(';'); - } - v = styleAttribute(); - advance(':'); - if (nexttoken.identifier && nexttoken.value === 'inherit') { - advance(); - } else { - if (!styleValue(v)) { - warning("Unexpected token '{a}'.", nexttoken, - nexttoken.value); - advance(); - } - } - if (nexttoken.id === '!') { - advance('!'); - adjacent(); - if (nexttoken.identifier && nexttoken.value === 'important') { - advance(); - } else { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'important', nexttoken.value); - } - } - if (nexttoken.id === '}' || nexttoken.id === xquote) { - warning("Missing '{a}'.", nexttoken, ';'); - } else { - advance(';'); - } - } - } - - function styleSelector() { - if (nexttoken.identifier) { - if (!is_own(htmltag, option.cap ? - nexttoken.value.toLowerCase() : nexttoken.value)) { - warning("Expected a tagName, and instead saw {a}.", - nexttoken, nexttoken.value); - } - advance(); - } else { - switch (nexttoken.id) { - case '>': - case '+': - advance(); - styleSelector(); - break; - case ':': - advance(':'); - switch (nexttoken.value) { - case 'active': - case 'after': - case 'before': - case 'checked': - case 'disabled': - case 'empty': - case 'enabled': - case 'first-child': - case 'first-letter': - case 'first-line': - case 'first-of-type': - case 'focus': - case 'hover': - case 'last-child': - case 'last-of-type': - case 'link': - case 'only-of-type': - case 'root': - case 'target': - case 'visited': - advance(); - break; - case 'lang': - advance(); - advance('('); - if (!nexttoken.identifier) { - warning("Expected a lang code, and instead saw :{a}.", - nexttoken, nexttoken.value); - } - advance(')'); - break; - case 'nth-child': - case 'nth-last-child': - case 'nth-last-of-type': - case 'nth-of-type': - advance(); - advance('('); - styleChild(); - advance(')'); - break; - case 'not': - advance(); - advance('('); - if (nexttoken.id === ':' && peek(0).value === 'not') { - warning("Nested not."); - } - styleSelector(); - advance(')'); - break; - default: - warning("Expected a pseudo, and instead saw :{a}.", - nexttoken, nexttoken.value); - } - break; - case '#': - advance('#'); - if (!nexttoken.identifier) { - warning("Expected an id, and instead saw #{a}.", - nexttoken, nexttoken.value); - } - advance(); - break; - case '*': - advance('*'); - break; - case '.': - advance('.'); - if (!nexttoken.identifier) { - warning("Expected a class, and instead saw #.{a}.", - nexttoken, nexttoken.value); - } - advance(); - break; - case '[': - advance('['); - if (!nexttoken.identifier) { - warning("Expected an attribute, and instead saw [{a}].", - nexttoken, nexttoken.value); - } - advance(); - if (nexttoken.id === '=' || nexttoken.value === '~=' || - nexttoken.value === '$=' || - nexttoken.value === '|=' || - nexttoken.id === '*=' || - nexttoken.id === '^=') { - advance(); - if (nexttoken.type !== '(string)') { - warning("Expected a string, and instead saw {a}.", - nexttoken, nexttoken.value); - } - advance(); - } - advance(']'); - break; - default: - error("Expected a CSS selector, and instead saw {a}.", - nexttoken, nexttoken.value); - } - } - } - - function stylePattern() { - if (nexttoken.id === '{') { - warning("Expected a style pattern, and instead saw '{a}'.", nexttoken, - nexttoken.id); - } - for (;;) { - styleSelector(); - if (nexttoken.id === '' || nexttoken.id === '{' || - nexttoken.id === '(end)') { - return ''; - } - if (nexttoken.id === ',') { - comma(); - } - } - } - - function stylelist() { - while (nexttoken.id !== '' && nexttoken.id !== '(end)') { - stylePattern(); - xmode = 'styleproperty'; - if (nexttoken.id === ';') { - advance(';'); - } else { - advance('{'); - substyle(); - xmode = 'style'; - advance('}'); - } - } - } - - function styles() { - var i; - while (nexttoken.id === '@') { - i = peek(); - advance('@'); - if (nexttoken.identifier) { - switch (nexttoken.value) { - case 'import': - advance(); - if (!cssUrl()) { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, 'url', nexttoken.value); - advance(); - } - advance(';'); - break; - case 'media': - advance(); - for (;;) { - if (!nexttoken.identifier || cssMedia[nexttoken.value] === true) { - error("Expected a CSS media type, and instead saw '{a}'.", nexttoken, nexttoken.id); - } - advance(); - if (nexttoken.id !== ',') { - break; - } - advance(','); - } - advance('{'); - stylelist(); - advance('}'); - break; - default: - warning("Expected an at-rule, and instead saw @{a}.", - nexttoken, nexttoken.value); - } - } else { - warning("Expected an at-rule, and instead saw '{a}'.", - nexttoken, nexttoken.value); - } - } - stylelist(); - } - - -// HTML parsing. - - function doBegin(n) { - if (n !== 'html' && !option.fragment) { - if (n === 'div' && option.adsafe) { - error("ADSAFE: Use the fragment option."); - } else { - error("Expected '{a}' and instead saw '{b}'.", - token, 'html', n); - } - } - if (option.adsafe) { - if (n === 'html') { - error( -"Currently, ADsafe does not operate on whole HTML documents. It operates on
CSS.
'); - } else if (data.json && !err) { + if (data.json && !err) { o.push('JSON: good.
'); } else if (data.globals) { o.push('