Skip to content

Commit

Permalink
Fixed lint issue and added a test placeholder. Will add more tests soon
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Jul 8, 2013
1 parent 655a316 commit 6d9bd1e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ CVS/
.svn
*~
.com.apple.timemachine.supported
coverage/
16 changes: 8 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ var treeify = require('treeify');
var license = require('./license');

var flatten = function(json) {
var moduleInfo = {licenses: UNKNOWN}
var moduleId;
var moduleInfo = {licenses: UNKNOWN},
licenseData;

data[json.name + '@' + json.version] = moduleInfo;


Expand All @@ -29,12 +29,12 @@ var flatten = function(json) {
}
}

var licenseData = json.license || json.licenses || undefined;
licenseData = json.license || json.licenses || undefined;
if (licenseData) {
if (Array.isArray(licenseData) && licenseData.length > 0) {
moduleInfo.licenses = licenseData.map(function(license){
if (typeof license === 'object') {
return license.type
return license.type;
} else if (typeof license === 'string') {
return license;
}
Expand All @@ -46,11 +46,11 @@ var flatten = function(json) {
}
} else if (json.readme){
moduleInfo.licenses = license(json.readme) || UNKNOWN;
}
}
if (json.dependencies) {
Object.keys(json.dependencies).forEach(function(name) {
var childDependency = json.dependencies[name];
var dependencyId = childDependency.name + '@' + childDependency.version;
var childDependency = json.dependencies[name],
dependencyId = childDependency.name + '@' + childDependency.version;
if (data[dependencyId]) { // already exists
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/license.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(str){
module.exports = function(str) {
if (str.indexOf('MIT') > -1) {
return 'MIT*';
} else if (str.indexOf('BSD') > -1) {
Expand All @@ -9,4 +9,4 @@ module.exports = function(str){
return 'WTF*';
}
return null;
}
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"devDependencies": {
"yui-lint": "~0.1.1",
"jshint": "~1.1.0",
"vows": "*"
"vows": "*",
"istanbul": "*"
},
"keywords": [
"license", "cli", "checker", "oss"
Expand Down
21 changes: 21 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var vows = require('vows'),
assert = require('assert'),
checker = require('../lib/index');

var tests = {
loading: {
topic: function() {
return checker;
},
'should load init': function(topic) {
assert.isFunction(topic.init);
},
'should load print': function(topic) {
assert.isFunction(topic.print);
}
}
};



vows.describe('license-checker').addBatch(tests).export(module);

0 comments on commit 6d9bd1e

Please sign in to comment.