From 2be2c7275459e13b32a5066b96c6216d4ed5d37c Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Sun, 7 Aug 2011 23:46:20 -0400 Subject: [PATCH] more jslinting --- js-assembler/runtime-src/baselib-hashes.js | 186 +++++++++--------- .../runtime-src/baselib-inspectors.js | 11 +- 2 files changed, 95 insertions(+), 102 deletions(-) diff --git a/js-assembler/runtime-src/baselib-hashes.js b/js-assembler/runtime-src/baselib-hashes.js index 41652de..e572f12 100644 --- a/js-assembler/runtime-src/baselib-hashes.js +++ b/js-assembler/runtime-src/baselib-hashes.js @@ -1,5 +1,10 @@ +/*jslint unparam: true, vars: true, white: true, newcap: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */ -(function(baselib) { +/*global Hashtable*/ + + +(function (baselib) { + 'use strict'; var exports = {}; baselib.hashes = exports; @@ -7,28 +12,28 @@ var _eqHashCodeCounter = 0; - var makeEqHashCode = function() { - _eqHashCodeCounter++; - return _eqHashCodeCounter; + var makeEqHashCode = function () { + _eqHashCodeCounter++; + return _eqHashCodeCounter; }; // getHashCode: any -> (or fixnum string) // Given a value, produces a hashcode appropriate for eq. - var getEqHashCode = function(x) { - if (typeof(x) === 'string') { - return x; - } - if (typeof(x) === 'number') { - return String(x); - } - if (x && !x._eqHashCode) { - x._eqHashCode = makeEqHashCode(); - } - if (x && x._eqHashCode) { - return x._eqHashCode; - } - return 0; + var getEqHashCode = function (x) { + if (typeof (x) === 'string') { + return x; + } + if (typeof (x) === 'number') { + return String(x); + } + if (x && !x._eqHashCode) { + x._eqHashCode = makeEqHashCode(); + } + if (x && x._eqHashCode) { + return x._eqHashCode; + } + return 0; }; @@ -36,9 +41,9 @@ // http://www.timdown.co.uk/jshashtable/ // // Defined to use the getEqHashCode defined in baselib_hash.js. - var makeLowLevelEqHash = function() { - return new Hashtable(function(x) { return getEqHashCode(x); }, - function(x, y) { return x === y; }); + var makeLowLevelEqHash = function () { + return new Hashtable(function (x) { return getEqHashCode(x); }, + function (x, y) { return x === y; }); }; @@ -52,51 +57,51 @@ ////////////////////////////////////////////////////////////////////// // Eq Hashtables - var EqHashTable = function(inputHash) { + var EqHashTable = function (inputHash) { this.hash = makeLowLevelEqHash(); this.mutable = true; }; - EqHashTable.prototype.toWrittenString = function(cache) { + EqHashTable.prototype.toWrittenString = function (cache) { var keys = this.hash.keys(); - var ret = []; - for (var i = 0; i < keys.length; i++) { - var keyStr = toWrittenString(keys[i], cache); - var valStr = toWrittenString(this.hash.get(keys[i]), cache); - ret.push('(' + keyStr + ' . ' + valStr + ')'); + var ret = [], i; + for (i = 0; i < keys.length; i++) { + var keyStr = baselib.format.toWrittenString(keys[i], cache); + var valStr = baselib.format.toWrittenString(this.hash.get(keys[i]), cache); + ret.push('(' + keyStr + ' . ' + valStr + ')'); } return ('#hasheq(' + ret.join(' ') + ')'); }; - EqHashTable.prototype.toDisplayedString = function(cache) { + EqHashTable.prototype.toDisplayedString = function (cache) { var keys = this.hash.keys(); - var ret = []; - for (var i = 0; i < keys.length; i++) { - var keyStr = toDisplayedString(keys[i], cache); - var valStr = toDisplayedString(this.hash.get(keys[i]), cache); - ret.push('(' + keyStr + ' . ' + valStr + ')'); + var ret = [], i; + for (i = 0; i < keys.length; i++) { + var keyStr = baselib.format.toDisplayedString(keys[i], cache); + var valStr = baselib.format.toDisplayedString(this.hash.get(keys[i]), cache); + ret.push('(' + keyStr + ' . ' + valStr + ')'); } return ('#hasheq(' + ret.join(' ') + ')'); }; - EqHashTable.prototype.equals = function(other, aUnionFind) { - if ( !(other instanceof EqHashTable) ) { - return false; + EqHashTable.prototype.equals = function (other, aUnionFind) { + if (!(other instanceof EqHashTable)) { + return false; } - if (this.hash.keys().length != other.hash.keys().length) { - return false; + if (this.hash.keys().length !== other.hash.keys().length) { + return false; } - var keys = this.hash.keys(); - for (var i = 0; i < keys.length; i++){ - if ( !(other.hash.containsKey(keys[i]) && - plt.baselib.equality.equals(this.hash.get(keys[i]), - other.hash.get(keys[i]), - aUnionFind)) ) { - return false; - } + var keys = this.hash.keys(), i; + for (i = 0; i < keys.length; i++) { + if (!(other.hash.containsKey(keys[i]) && + baselib.equality.equals(this.hash.get(keys[i]), + other.hash.get(keys[i]), + aUnionFind))) { + return false; + } } return true; }; @@ -105,55 +110,55 @@ ////////////////////////////////////////////////////////////////////// // Equal hash tables - var EqualHashTable = function(inputHash) { - this.hash = new _Hashtable( - function(x) { - return plt.baselib.format.toWrittenString(x); - }, - function(x, y) { - return plt.baselib.equality.equals(x, y, new plt.baselib.UnionFind()); - }); - this.mutable = true; + var EqualHashTable = function (inputHash) { + this.hash = new Hashtable( + function (x) { + return baselib.format.toWrittenString(x); + }, + function (x, y) { + return baselib.equality.equals(x, y, new baselib.UnionFind()); + }); + this.mutable = true; }; - EqualHashTable.prototype.toWrittenString = function(cache) { + EqualHashTable.prototype.toWrittenString = function (cache) { var keys = this.hash.keys(); - var ret = []; - for (var i = 0; i < keys.length; i++) { - var keyStr = plt.baselib.format.toWrittenString(keys[i], cache); - var valStr = plt.baselib.format.toWrittenString(this.hash.get(keys[i]), cache); - ret.push('(' + keyStr + ' . ' + valStr + ')'); + var ret = [], i; + for (i = 0; i < keys.length; i++) { + var keyStr = baselib.format.toWrittenString(keys[i], cache); + var valStr = baselib.format.toWrittenString(this.hash.get(keys[i]), cache); + ret.push('(' + keyStr + ' . ' + valStr + ')'); } return ('#hash(' + ret.join(' ') + ')'); }; - EqualHashTable.prototype.toDisplayedString = function(cache) { + EqualHashTable.prototype.toDisplayedString = function (cache) { var keys = this.hash.keys(); - var ret = []; - for (var i = 0; i < keys.length; i++) { - var keyStr = plt.baselib.format.toDisplayedString(keys[i], cache); - var valStr = plt.baselib.format.toDisplayedString(this.hash.get(keys[i]), cache); - ret.push('(' + keyStr + ' . ' + valStr + ')'); + var ret = [], i; + for (i = 0; i < keys.length; i++) { + var keyStr = baselib.format.toDisplayedString(keys[i], cache); + var valStr = baselib.format.toDisplayedString(this.hash.get(keys[i]), cache); + ret.push('(' + keyStr + ' . ' + valStr + ')'); } return ('#hash(' + ret.join(' ') + ')'); }; - EqualHashTable.prototype.equals = function(other, aUnionFind) { + EqualHashTable.prototype.equals = function (other, aUnionFind) { if ( !(other instanceof EqualHashTable) ) { - return false; + return false; } - if (this.hash.keys().length != other.hash.keys().length) { - return false; + if (this.hash.keys().length !== other.hash.keys().length) { + return false; } - var keys = this.hash.keys(); - for (var i = 0; i < keys.length; i++){ - if (! (other.hash.containsKey(keys[i]) && - plt.baselib.equality.equals(this.hash.get(keys[i]), - other.hash.get(keys[i]), - aUnionFind))) { - return false; - } + var keys = this.hash.keys(), i; + for (i = 0; i < keys.length; i++){ + if (! (other.hash.containsKey(keys[i]) && + baselib.equality.equals(this.hash.get(keys[i]), + other.hash.get(keys[i]), + aUnionFind))) { + return false; + } } return true; }; @@ -161,27 +166,12 @@ - var isHash = function(x) { + var isHash = function (x) { return (x instanceof EqHashTable || - x instanceof EqualHashTable); + x instanceof EqualHashTable); }; - - - - - - - - - - - - - - - ////////////////////////////////////////////////////////////////////// exports.getEqHashCode = getEqHashCode; @@ -194,4 +184,4 @@ exports.isHash = isHash; -})(this['plt'].baselib); \ No newline at end of file +}(this.plt.baselib)); \ No newline at end of file diff --git a/js-assembler/runtime-src/baselib-inspectors.js b/js-assembler/runtime-src/baselib-inspectors.js index efc5645..ae4a7d7 100644 --- a/js-assembler/runtime-src/baselib-inspectors.js +++ b/js-assembler/runtime-src/baselib-inspectors.js @@ -1,15 +1,18 @@ +/*jslint vars: true, maxerr: 50, indent: 4 */ + // Structure types -(function(baselib) { +(function (baselib) { + 'use strict'; var exports = {}; baselib.inspectors = exports; - var Inspector = function() { + var Inspector = function () { }; var DEFAULT_INSPECTOR = new Inspector(); - Inspector.prototype.toString = function() { + Inspector.prototype.toString = function () { return "#"; }; @@ -23,4 +26,4 @@ exports.isInspector = isInspector; -})(this['plt'].baselib); \ No newline at end of file +}(this.plt.baselib)); \ No newline at end of file