Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

groove

  • Loading branch information...
commit 35ec4a53a31c4b42dfa2eed7776c4d2f4c616f28 1 parent d4a0702
@douglascrockford authored
Showing with 95 additions and 203 deletions.
  1. +4 −4 README
  2. +4 −4 fulljslint.js
  3. +86 −0 intercept.js
  4. +1 −7 lint.html
  5. +0 −188 web.js
View
8 README
@@ -3,15 +3,15 @@ JSLint, The JavaScript Code Quality Tool
Douglas Crockford
douglas@crockford.com
-2010-11-12
+2010-11-18
fulljslint.js contains the fully commented JSLINT function.
fulljslint.html runs the JSLINT function in a web page. The page also depends
-on adsafe.js and json2.js (which are not included in this project) and web.js
-(which is).
+on adsafe.js and json2.js (which are not included in this project) and
+intercept.js (which is).
-web.js scripts the fulljslint.html ui.
+intercept.js scripts the fulljslint.html ui by augmenting ADsafe.
rhino.js is a sample companion script to run fulljslint.js on Rhino.
View
8 fulljslint.js
@@ -1,5 +1,5 @@
// jslint.js
-// 2010-11-17
+// 2010-11-18
/*
Copyright (c) 2002 Douglas Crockford (www.JSLint.com)
@@ -3058,8 +3058,8 @@ loop: for (;;) {
cssBorderStyle = [
- 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'ridge',
- 'inset', 'outset'
+ 'none', 'dashed', 'dotted', 'double', 'groove',
+ 'hidden', 'inset', 'outset', 'ridge', 'solid'
];
cssBreak = [
@@ -5779,7 +5779,7 @@ loop: for (;;) {
};
itself.jslint = itself;
- itself.edition = '2010-11-17';
+ itself.edition = '2010-11-18';
return itself;
View
86 intercept.js
@@ -0,0 +1,86 @@
+// intercept.html
+// 2009-08-21
+
+// This file makes it possible for JSLint to run as an ADsafe widget by
+// adding lib features.
+
+// It provides a JSON cookie facility. Each widget is allowed to create a
+// single JSON cookie.
+
+// It also provides a way for the widget to call JSLint. The widget cannot
+// call JSLint directly because it is loaded as a global variable. I don't
+// want to change that because other versions of JSLint depend on that.
+
+/*jslint nomen: false */
+
+/*global ADSAFE, document, JSLINT */
+
+/*members ___nodes___, _intercept, cookie, edition, get, getTime,
+ indexOf, innerHTML, jslint, length, parse, replace, report, set,
+ setTime, slice, stringify, toGMTString
+*/
+
+
+"use strict";
+ADSAFE._intercept(function (id, dom, lib, bunch) {
+
+// Give every widget access to a cookie. The name of the cookie will be the
+// same as the id of the widget.
+
+ lib.cookie = {
+ get: function () {
+
+// Get the raw cookie. Extract this widget's cookie, and parse it.
+
+ var c = ' ' + document.cookie + ';',
+ s = c.indexOf((' ' + id + '=')),
+ v;
+ try {
+ if (s >= 0) {
+ s += id.length + 2;
+ v = JSON.parse(c.slice(s, c.indexOf(';', s)));
+ }
+ } catch (ignore) {}
+ return v;
+ },
+ set: function (value) {
+
+// Set a cookie. It must be under 2000 in length. Escapify equal sign
+// and semicolon if necessary.
+
+ var d,
+ j = JSON.stringify(value)
+ .replace(/[=]/g, '\\u003d')
+ .replace(/[;]/g, '\\u003b');
+
+ if (j.length < 2000) {
+ d = new Date();
+ d.setTime(d.getTime() + 1e9);
+ document.cookie = id + "=" + j +
+ ';expires=' + d.toGMTString();
+ }
+ }
+ };
+});
+
+ADSAFE._intercept(function (id, dom, lib, bunch) {
+
+// Give only the JSLINT_ widget access to the JSLINT function.
+// We add a jslint function to its lib that calls JSLINT and
+// then calls JSLINT.report, and stuffs the html result into
+// a node provided by the widget. A widget does not get direct
+// access to nodes.
+
+// We also add an edition function to the lib that gives the
+// widget access to the current edition string.
+
+ if (id === 'JSLINT_') {
+ lib.jslint = function (source, options, output) {
+ JSLINT(source, options);
+ output.___nodes___[0].innerHTML = JSLINT.report();
+ };
+ lib.edition = function () {
+ return JSLINT.edition;
+ };
+ }
+});
View
8 lint.html 100644 → 100755
@@ -726,13 +726,7 @@ <h2 id=try>Try it</h2>
<h2 id=implementation>Implementation</h2>
<p><code>JSLint</code> uses a <a href="http://javascript.crockford.com/tdop/tdop.html">Pratt
Parser (Top Down Operator Precedence)</a>. It is written in JavaScript.
- The full source code is available:</p>
-<ul>
- <li><a href="http://www.JSLint.com/fulljslint.js"><code>fulljslint.js</code></a></li>
- <li><code><a href="http://www.JSON.org/json2.js">json2.js</a> <a href="http://www.ADsafe.org/adsafe.js">adsafe.js</a> <a href="http://www.JSLint.com/intercept.js">intercept.js</a> <a href="http://www.JSLint.com/widget.js">widget.js</a></code></li>
- <li><code><a href="rhino/rhino.js">rhino.js</a></code></li>
- <li><code><a href="wsh/wsh.js">wsh.js</a></code></li>
-</ul>
+ The full source code is available: <a href="https://github.com/douglascrockford/JSLint">https://github.com/douglascrockford/JSLint</a>.</p>
<a href="http://www.JSLint.com/"><img src="jslintpill.gif" width="36" height="17" border="0"></a>
<a href="http://www.ADsafe.org/"><img src="adsafepill.gif" width="36" height="17" border="0"></a>
<a href="http://www.JSON.org/"><img src="jsonpill.gif" width="36" height="17" border="0"></a>
View
188 web.js
@@ -1,188 +0,0 @@
-// web.js
-// 2010-04-05
-
-// This is the web browser companion to fulljslint.js.
-
-/*jslint browser: true, evil: true */
-/*members checked, clearall, cookie, edition, getElementById, getElementsByName,
- getTime, goodparts, indent, indexOf, innerHTML, join, length, maxerr,
- onchange, onclick, parse, predef, push, recommended, report, select,
- setTime, sort, split, stringify, substring, toGMTString, value
-*/
-
-
-"use strict";
-
-var JSLINT;
-
-(function () {
- var c = document.cookie,
- predefined = document.getElementById('predef'),
- cluster = {
- goodparts: [
- 'bitwise', 'eqeqeq', 'immed', 'newcap', 'nomen', 'onevar',
- 'plusplus', 'regexp', 'undef', 'white'
- ],
- clearall: []
- },
- i, // Loop counter
- indent = document.getElementById('indent'),
- input = document.getElementById('input'),
- jslintstring = document.getElementById('jslintstring'),
- maxerr = document.getElementById('maxerr'),
- n, // A dom node
- ns, // An array of dom nodes
- nclear,
- nclick,
- o, // The options object
- options = [
- 'adsafe', 'bitwise', 'browser', 'cap', 'css', 'debug', 'devel',
- 'eqeqeq', 'es5', 'evil', 'forin', 'fragment', 'immed', 'laxbreak',
- 'newcap', 'nomen', 'on', 'onevar', 'passfail', 'plusplus', 'regexp',
- 'rhino', 'safe', 'windows', 'strict', 'sub', 'undef', 'white',
- 'widget'
- ],
- output = document.getElementById('output');
-
- function get_check(o) {
- var n = document.getElementById(o);
- return n && n.checked;
- }
-
-
- function set_check(o, b) {
- var n = document.getElementById(o);
- if (n) {
- n.checked = b;
- }
- }
-
- function show_jslint_options() {
- var a = [], j, oj, s;
- for (j = 0; j < options.length; j += 1) {
- oj = options[j];
- if (get_check(oj)) {
- a.push(oj + ': true');
- }
- }
- if (!get_check('passfail') && +maxerr.value > 0) {
- a.push('maxerr: ' + maxerr.value);
- }
- if (get_check('white') && +indent.value > 0) {
- a.push('indent: ' + indent.value);
- }
- s = '/*jslint ' + a.join(', ') + ' */';
- jslintstring.innerHTML = s;
- }
-
- function set_cluster(n) {
- document.getElementById(n).onclick = function (e) {
- var c = cluster[n];
- for (i = 0; i < options.length; i += 1) {
- set_check(options[i], false);
- }
- for (i = 0; i < c.length; i += 1) {
- set_check(c[i], true);
- }
- indent.value = '4';
- maxerr.value = '50';
- predefined.value = '';
- };
-
-// Show the jslintstring options.
-
- show_jslint_options();
- }
-
-
- input.onchange = function (e) {
- output.innerHTML = '';
- };
-
-// Display the edition.
-
- document.getElementById('edition').innerHTML = 'Edition ' + JSLINT.edition;
-
-// Add click event handlers to the [JSLint] and [clear] buttons.
-
- ns = document.getElementsByName('jslint');
- nclick = function (e) {
-
-// Make a JSON cookie of the current options.
-
- var d = new Date(), j, oj, op = {};
- for (j = 0; j < options.length; j += 1) {
- oj = options[j];
- op[oj] = get_check(oj);
- }
- op.indent = +indent.value || 4;
- op.maxerr = +maxerr.value || 50;
- oj = predefined.value;
- if (oj) {
- op.predef = oj.split(/\s*,\s*/);
- }
- d.setTime(d.getTime() + 1e10);
- document.cookie = 'jslint=' + JSON.stringify(op) + ';expires=' +
- d.toGMTString();
-
-// Call JSLint and obtain the report.
-
- JSLINT(input.value, op);
- output.innerHTML = JSLINT.report();
- input.select();
- return false;
- };
- nclear = function (e) {
- input.value = '';
- output.innerHTML = '';
- input.select();
- return false;
- };
- for (i = 0; i < ns.length; i += 1) {
- n = ns[i];
- switch (n.value) {
- case 'JSLint':
- n.onclick = nclick;
- break;
- case 'clear':
- n.onclick = nclear;
- break;
- }
- }
-
- indent.onchange = maxerr.onchange = predefined.onchange =
- document.getElementById('options').onclick = function (e) {
- show_jslint_options();
- };
-
-
-// Recover the JSLint options from a JSON cookie.
-
- if (c && c.length > 8) {
- i = c.indexOf('jslint={');
- if (i >= 0) {
- c = c.substring(i + 7);
- i = c.indexOf('}');
- if (i > 1) {
- c = c.substring(0, i + 1);
- o = JSON.parse(c);
- for (i = 0; i < options.length; i += 1) {
- set_check(options[i], o[options[i]]);
- }
- indent.value = o.indent || 4;
- maxerr.value = o.maxerr || 50;
- predefined.value = o.predef instanceof Array ?
- o.predef.join(',') : '';
- }
- }
- }
-
-// Show the jslintstring options.
-
- show_jslint_options();
-
- set_cluster('goodparts');
- set_cluster('clearall');
-
- input.select();
-}());
Please sign in to comment.
Something went wrong with that request. Please try again.