Skip to content

Commit

Permalink
remove Array prototype extensions fixes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
staxmanade committed Feb 25, 2017
1 parent c333ab1 commit 7b807de
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions lib/Approvals.js
Expand Up @@ -34,13 +34,11 @@ process.on('exit', function () {
return file.replace(/\\/g, "/");
});

/* eslint-disable no-extend-native */

// TODO rework to remove adding function to prototype
Array.prototype.unique = function () {
var o = {}, i, l = this.length, r = [];
var unique = function (items) {
var o = {}, i, l = items.length, r = [];
for (i = 0; i < l; i += 1) {
o[this[i]] = this[i];
o[items[i]] = items[i];
}
for (i in o) {
if (o.hasOwnProperty(i)) {
Expand All @@ -50,33 +48,31 @@ process.on('exit', function () {
return r;
};

var flatten = Function.prototype.apply.bind(Array.prototype.concat, []);

Array.prototype.selectMany = function (fn) {
return flatten(this.map(fn));
var selectMany = function (items, fn) {
var flatten = Function.prototype.apply.bind(Array.prototype.concat, []);
return flatten(items.map(fn));
};
/* eslint-enable no-extend-native */

staleApprovals = listOfApprovedFiles
.map(function (file) { return path.dirname(file); }) // get just the directory of each approved file.
.unique() // hmm only unique directories
staleApprovals = unique(listOfApprovedFiles.map(function (file) { return path.dirname(file); })) // get just the directory of each approved file.
// hmm only unique directories
.map(function (folder) {
return glob.sync(folder + "**/*.approved.*").filter(function (file) {
return !listOfApprovedFiles[file];
});
}) // use 'glob' to find all .approved.* files for each folder.
.selectMany(function (files) {
return files;
}) // turn the array of array's into a single array of strings.
.filter(function (file) {
if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
return !options.shouldIgnoreStaleApprovedFile(file);
}
return true;
})
.filter(function (item) {
return listOfApprovedFiles.indexOf(item) < 0;
}); // only pull the ones that aren't already in the 'listOfApprovedFiles'
}); // use 'glob' to find all .approved.* files for each folder.

staleApprovals = selectMany(selectMany, function (files) {
return files;
}) // turn the array of array's into a single array of strings.
.filter(function (file) {
if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
return !options.shouldIgnoreStaleApprovedFile(file);
}
return true;
})
.filter(function (item) {
return listOfApprovedFiles.indexOf(item) < 0;
}); // only pull the ones that aren't already in the 'listOfApprovedFiles'

if (staleApprovals.length) {
throw new Error('ERROR: Found stale approvals files: \n - ' + staleApprovals.join('\n - ') + '\n');
Expand Down

0 comments on commit 7b807de

Please sign in to comment.