Permalink
Browse files

pretty capable nesting integration algorithm

  • Loading branch information...
1 parent bc9db07 commit e6473ce4c6ef89f6d86e8821408ae9a05b35f220 @substack committed Aug 12, 2012
Showing with 41 additions and 5 deletions.
  1. +1 −1 index.js
  2. +37 −1 lib/complexity.js
  3. +3 −3 readme.markdown
View
@@ -31,7 +31,7 @@ module.exports = function (dir, cb) {
walk(file, function () {
emitter.emit('end');
});
- }.bind(null, require.resolve(dir + '/')));
+ }.bind(null, require.resolve(/\.js$/.test(dir) ? dir : dir + '/')));
var walked = {};
View
@@ -1,5 +1,10 @@
+var falafel = require('falafel');
+
module.exports = function (src) {
- return { lines : lines(src) };
+ return {
+ lines : lines(src),
+ nested : nested(src)
+ };
};
function lines (src) {
@@ -8,3 +13,34 @@ function lines (src) {
}).length
return -Math.pow(n, 1.2) / 50;
}
+
+function nested (src) {
+ var costs = {
+ FunctionDeclaration : 4,
+ FunctionExpression : 4,
+ ForStatement : 5,
+ WhileStatement : 5,
+ Literal : 2,
+ IfStatement : 3,
+ SwitchStatement : 20
+ };
+
+ var sum = 0;
+ falafel(src, function (node) {
+ sum -= parents(node)
+ .slice(1)
+ .reduce(function (sum, p) {
+ return sum * (costs[p.type] || 1.05);
+ }, 0.1)
+ / 500
+ ;
+ });
+ return sum;
+}
+
+function parents (node) {
+ for (var res = []; node.parent; node = node.parent) {
+ res.push(node.parent);
+ }
+ return res;
+}
View
@@ -1,9 +1,9 @@
# codebux
-This module computes technical debt for node programs.
+This program computes technical debt for node programs.
-Lines of code are spent. You start at $100. You don't get any more codebux. You
-can only lose codebux by fucking up somehow. There are many ways to fuck up:
+Lines of code are spent. You start at $100. You don't get any more codebux.
+There are many ways to fuck up:
* too much code
* too much indentation

0 comments on commit e6473ce

Please sign in to comment.