Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

-- lint

  • Loading branch information...
commit 544fcdfb4c7eaf7c7069edde399e071966ef98ed 1 parent f3ad88d
@medikoo authored
View
1  .gitignore
@@ -1,3 +1,4 @@
.DS_Store
/node_modules
/npm-debug.log
+/.lintcache
View
45 .lint
@@ -0,0 +1,45 @@
+@root
+
+indent 2
+maxlen 80
+es5
+
+jslint_medikoo.tabs
+jslint_medikoo.module
+jslint_medikoo.plusplus
+jslint_medikoo.nomen
+
+jshint.laxcomma
+jshint.camelcase
+jshint.curly
+jshint.eqeqeq
+jshint.forin
+jshint.immed
+jshint.latedef
+jshint.newcap
+jshint.noarg
+jshint.noempty
+jshint.nonew
+jshint.regexp
+jshint.undef
+jshint.unused
+jshint.strict
+jshint.trailing
+jshint.globalstrict
+jshint.global module, require, exports
+jshint.smarttabs
+jshint.eqnull
+jshint.expr
+
+./lib/memoize.js
+jslint_medikoo.bitwise
+jslint_medikoo.predef+ setTimeout
+jshint.global+ setTimeout
+
+./lib/profile.js
+jslint_medikoo.predef+ console
+jshint.global+ console
+
+./test/memoize.js
+jslint_medikoo.predef+ setTimeout
+jshint.global+ setTimeout
View
30 lib/memoize.js
@@ -9,17 +9,17 @@ var global = require('es5-ext/lib/global')
, partial = require('es5-ext/lib/Function/prototype/partial')
, callable = require('es5-ext/lib/Object/valid-callable')
, isCallable = require('es5-ext/lib/Object/is-callable')
+ , isCopy = require('es5-ext/lib/Object/is-copy')
, forEach = require('es5-ext/lib/Object/for-each')
, isString = require('es5-ext/lib/String/is-string')
, nextTick = require('next-tick')
- , isArray = Array.isArray, join = Array.prototype.join
- , map = Array.prototype.map, push = Array.prototype.push
+ , join = Array.prototype.join, push = Array.prototype.push
, slice = Array.prototype.slice, now = Date.now
, apply = Function.prototype.apply, create = Object.create
, defineProperty = Object.defineProperty
- , resolve, memoize, id = 0;
+ , resolve, memoize;
resolve = function (args) {
return this.map(function (r, i) {
@@ -78,12 +78,12 @@ memoize = module.exports = function (fn/*, options*/) {
if (options.method) {
if (isString(options.method)) {
method = { name: String(options.method),
- descriptor: { configurable: true, writable: true } }
+ descriptor: { configurable: true, writable: true } };
} else {
method = options.method;
method.name = String(method.name);
method.descriptor = (method.descriptor == null) ?
- { configurable: true, writable: true } : Object(method.descriptor);
+ { configurable: true, writable: true } : Object(method.descriptor);
}
options = create(options);
options.method = undefined;
@@ -168,7 +168,7 @@ memoize = module.exports = function (fn/*, options*/) {
};
clear = function (length, args) {
- var index = 0, rset = cache, i, path = [], value;
+ var index = 0, rset = cache, i, path = [];
if (length === 0) {
delete rset[length];
@@ -208,10 +208,10 @@ memoize = module.exports = function (fn/*, options*/) {
args = slice.call(args, 0, length);
} else if (length > argsLength) {
args = toArray(args);
- push.apply(args, Array(length - argsLength));
+ push.apply(args, new Array(length - argsLength));
}
return (length > 1) ? join.call(args, '\u0001') :
- (args[0] + '\u0002');
+ (args[0] + '\u0002');
} else {
return '';
}
@@ -231,7 +231,7 @@ memoize = module.exports = function (fn/*, options*/) {
initAsync = function (args, cb, maxAgeData) {
var waiting = cb ? [cb] : []
, value = { waiting: waiting }, time;
- args.push(function (err, result) {
+ args.push(function (err) {
var args2 = arguments;
if (profile) {
profile.time += (now() - time);
@@ -271,7 +271,7 @@ memoize = module.exports = function (fn/*, options*/) {
};
mfn = function () {
- var args, alength, id, cb, mcb, waiting, time;
+ var args, alength, id, cb, time;
if (method && this && (this !== global)) {
method.descriptor.value = memoize(fn.bind(this), options);
defineProperty(this, method.name, method.descriptor);
@@ -413,11 +413,11 @@ memoize = module.exports = function (fn/*, options*/) {
} else {
if (max) {
if (find.call(queue, function (data, index) {
- if (isCopy(data, [alength, args], 2)) {
- id = index;
- return true;
- }
- })) {
+ if (isCopy(data, [alength, args], 2)) {
+ id = index;
+ return true;
+ }
+ })) {
queue.splice(id, 1);
}
}
View
2  lib/profile.js
@@ -22,7 +22,7 @@ memoize._profile = function () {
exports.log = function () {
var initial, cached, time, ordered, ipad, cpad, ppad, toPrc, tpad, atime;
- initial = cached = time = stime = 0;
+ initial = cached = time = 0;
ordered = [];
toPrc = function (initial, cached) {
if (!initial && !cached) {
View
66 test/memoize.js
@@ -120,13 +120,13 @@ module.exports = function (t, a) {
},
"Original arguments": function (a) {
var fn, mfn, x = {};
- fn = function (x, y) { return toArray(mfn.args); };
+ fn = function (x, y) { x = y; return toArray(mfn.args); };
mfn = t(fn);
a.deep(mfn(23, 'raz', x), [23, 'raz', x]);
},
"Resolvers": function () {
- var i = 0, fn, fn2, r, j = 0, z;
+ var i = 0, fn, r;
fn = t(function () { ++i; return arguments; },
{ length: 3, resolvers: [Boolean, String] });
return {
@@ -158,14 +158,14 @@ module.exports = function (t, a) {
},
"Clear Cache": {
"Specific": function () {
- var i = 0, fn, mfn, r, x = {};
+ var i = 0, fn, mfn, x = {};
fn = function (a, b, c) {
if (c === 3) {
++i;
}
return arguments;
- }
+ };
mfn = t(fn);
mfn(1, x, 3);
@@ -189,14 +189,14 @@ module.exports = function (t, a) {
a(i, 1, "Proper no arguments clear");
},
"All": function () {
- var i = 0, fn, r, x = {};
+ var i = 0, fn, x = {};
- fn = function (a, b, c) {
+ fn = function () {
++i;
return arguments;
- }
+ };
- fn = t(fn);
+ fn = t(fn, { length: 3 });
fn(1, x, 3);
fn(1, x, 4);
fn(1, x, 3);
@@ -248,7 +248,7 @@ module.exports = function (t, a) {
},
"One arg": function (a) {
var i = 0, fn = function (x) { ++i; return x; }, mfn
- , y = { toString: function () { return 'foo' } };
+ , y = { toString: function () { return 'foo'; } };
mfn = t(fn, { primitive: true });
a(mfn(y), y, "#1");
a(mfn('foo'), y, "#2");
@@ -256,7 +256,7 @@ module.exports = function (t, a) {
},
"Many args": function (a) {
var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn
- , y = { toString: function () { return 'foo' } };
+ , y = { toString: function () { return 'foo'; } };
mfn = t(fn, { primitive: true });
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#1");
a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2");
@@ -264,7 +264,7 @@ module.exports = function (t, a) {
},
"Clear cache": function (a) {
var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn
- , y = { toString: function () { return 'foo' } };
+ , y = { toString: function () { return 'foo'; } };
mfn = t(fn, { primitive: true });
a(mfn(y, 'bar', 'zeta'), 'foobarzeta', "#1");
a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2");
@@ -286,7 +286,7 @@ module.exports = function (t, a) {
mfn(3, 5, 7);
a(mfn.clearRef(3, 5, 7), false, "Clear #2");
mfn(3, 5, 7);
- a(mfn.clearRef(3, 5, 7), false , "Clear #3");
+ a(mfn.clearRef(3, 5, 7), false, "Clear #3");
mfn(3, 5, 7);
a(i, 1, "Not cleared");
a(mfn.clearRef(3, 5, 7), false, "Clear #4");
@@ -650,9 +650,9 @@ module.exports = function (t, a) {
}
},
"MaxAge": {
- "Regular" : {
+ "Regular": {
"Sync": function (a, d) {
- var mfn, fn, u = {}, i = 0;
+ var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return x + y;
@@ -746,9 +746,9 @@ module.exports = function (t, a) {
}, 20);
}
},
- "Primitive" : {
+ "Primitive": {
"Sync": function (a, d) {
- var mfn, fn, u = {}, i = 0;
+ var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return x + y;
@@ -844,9 +844,9 @@ module.exports = function (t, a) {
}
},
"Max": {
- "Regular" : {
+ "Regular": {
"Sync": function (a) {
- var mfn, fn, u = {}, i = 0;
+ var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return x + y;
@@ -911,7 +911,6 @@ module.exports = function (t, a) {
a.deep([err, res], [null, 13], "Result B #1");
a(i, 2, "Called B #1");
-
a(mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
a(i, 2, "Called #3");
@@ -981,9 +980,9 @@ module.exports = function (t, a) {
}), u, "Initial #1");
}
},
- "Primitive" : {
+ "Primitive": {
"Sync": function (a) {
- var mfn, fn, u = {}, i = 0;
+ var mfn, fn, i = 0;
fn = function (x, y) {
++i;
return x + y;
@@ -1048,7 +1047,6 @@ module.exports = function (t, a) {
a.deep([err, res], [null, 13], "Result B #1");
a(i, 2, "Called B #1");
-
a(mfn(3, 7, function (err, res) {
a.deep([err, res], [null, 10], "Result #3");
a(i, 2, "Called #3");
@@ -1120,9 +1118,9 @@ module.exports = function (t, a) {
}
},
"Dispose": {
- "Regular" : {
+ "Regular": {
"Sync": function (a) {
- var mfn, fn, u = {}, i = 0, value = [];
+ var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
@@ -1140,7 +1138,7 @@ module.exports = function (t, a) {
a.deep(value, [16], "#2");
},
"Ref counter": function (a) {
- var mfn, fn, u = {}, i = 0, value = [];
+ var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
@@ -1174,9 +1172,9 @@ module.exports = function (t, a) {
mfn = t(fn, { async: true,
dispose: function (val) { value.push(val); } });
- mfn(3, 7, function (err, res) {
- mfn(5, 8, function (err, res) {
- mfn(12, 4, function (err, res) {
+ mfn(3, 7, function () {
+ mfn(5, 8, function () {
+ mfn(12, 4, function () {
a.deep(value, [], "Pre");
mfn.clear(5, 8);
a.deep(value, [13], "#1");
@@ -1189,9 +1187,9 @@ module.exports = function (t, a) {
});
}
},
- "Primitive" : {
+ "Primitive": {
"Sync": function (a) {
- var mfn, fn, u = {}, i = 0, value = [];
+ var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
@@ -1209,7 +1207,7 @@ module.exports = function (t, a) {
a.deep(value, [16], "#2");
},
"Ref counter": function (a) {
- var mfn, fn, u = {}, i = 0, value = [];
+ var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
@@ -1243,9 +1241,9 @@ module.exports = function (t, a) {
mfn = t(fn, { async: true,
dispose: function (val) { value.push(val); } });
- mfn(3, 7, function (err, res) {
- mfn(5, 8, function (err, res) {
- mfn(12, 4, function (err, res) {
+ mfn(3, 7, function () {
+ mfn(5, 8, function () {
+ mfn(12, 4, function () {
a.deep(value, [], "Pre");
mfn.clear(5, 8);
a.deep(value, [13], "#1");
View
2  test/profile.js
@@ -1,6 +1,6 @@
'use strict';
-var memoize = require('../lib/memoize')
+var memoize = require('../lib/memoize');
module.exports = function (t, a) {
a(typeof memoize._profile, 'function', "Set on memoize");
Please sign in to comment.
Something went wrong with that request. Please try again.