Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Chore: Refactor the codebase (fixes #220) #261

Merged
merged 1 commit into from
May 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
root: true

env:
node: true

extends: eslint
plugins:
- node
extends:
- "eslint"
- "plugin:node/recommended"
rules:
no-undefined: "off"
lines-around-comment: "off"
newline-after-var: "off"
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: node_js
sudo: false
node_js:
- "0.12"
- 4
- 6
- "4"
- "5"
- "6"
- "7"
after_success:
- npm run coveralls
52 changes: 21 additions & 31 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@

require("shelljs/make");

var checker = require("npm-license"),
const checker = require("npm-license"),
nodeCLI = require("shelljs-nodecli");

//------------------------------------------------------------------------------
// Settings
//------------------------------------------------------------------------------

var OPEN_SOURCE_LICENSES = [
const OPEN_SOURCE_LICENSES = [
/MIT/, /BSD/, /Apache/, /ISC/, /WTF/, /Public Domain/
];

//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------

var NODE_MODULES = "./node_modules/",
const NODE_MODULES = "./node_modules/",

// Utilities - intentional extra space at the end of each string
MOCHA = NODE_MODULES + "mocha/bin/_mocha ",
MOCHA = `${NODE_MODULES}mocha/bin/_mocha `,

// Files
MAKEFILE = "./Makefile.js",
/* eslint-disable no-use-before-define */
JS_FILES = find("lib/").filter(fileType("js")).join(" ") + " parser.js",
JS_FILES = `${find("lib/").filter(fileType("js")).join(" ")} parser.js`,
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" ");
/* eslint-enable no-use-before-define */

Expand Down Expand Up @@ -67,7 +67,7 @@ target.all = function() {
};

target.lint = function() {
var errors = 0,
let errors = 0,
lastReturn;

echo("Validating Makefile.js");
Expand Down Expand Up @@ -96,10 +96,8 @@ target.lint = function() {
target.test = function() {
target.lint();

var errors = 0,
lastReturn;

lastReturn = nodeCLI.exec("istanbul", "cover", MOCHA, "-- -c", TEST_FILES);
const lastReturn = nodeCLI.exec("istanbul", "cover", MOCHA, "-- -c", TEST_FILES);
let errors = 0;

if (lastReturn.code !== 0) {
errors++;
Expand All @@ -122,42 +120,34 @@ target.checkLicenses = function() {

/**
* Returns true if the given dependency's licenses are all permissable for use in OSS
* @param {object} dependency object containing the name and licenses of the given dependency
* @param {Object} dependency object containing the name and licenses of the given dependency
* @returns {boolean} is permissable dependency
*/
function isPermissible(dependency) {
var licenses = dependency.licenses;
const licenses = dependency.licenses;

if (Array.isArray(licenses)) {
return licenses.some(function(license) {
return isPermissible({
name: dependency.name,
licenses: license
});
});
return licenses.some(license => isPermissible({
name: dependency.name,
licenses: license
}));
}

return OPEN_SOURCE_LICENSES.some(function(license) {
return license.test(licenses);
});
return OPEN_SOURCE_LICENSES.some(license => license.test(licenses));
}

echo("Validating licenses");

checker.init({
start: __dirname
}, function(deps) {
var impermissible = Object.keys(deps).map(function(dependency) {
return {
name: dependency,
licenses: deps[dependency].licenses
};
}).filter(function(dependency) {
return !isPermissible(dependency);
});
}, deps => {
const impermissible = Object.keys(deps).map(dependency => ({
name: dependency,
licenses: deps[dependency].licenses
})).filter(dependency => !isPermissible(dependency));

if (impermissible.length) {
impermissible.forEach(function(dependency) {
impermissible.forEach(dependency => {
console.error("%s license for %s is impermissible.",
dependency.licenses,
dependency.name
Expand Down
Loading