Skip to content

Commit

Permalink
fixing codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cope committed Aug 18, 2018
1 parent d1a8649 commit db0766c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ function extractArrays(parent) {
return myArrays;
}

function processObjects(beforeObjects, afterObjects, root) {
const nonMatchingArrays = (b, a) => (_.isArray(b) && !_.isArray(a)) || (_.isArray(a) && !_.isArray(b));
const bothArrays = (b, a) => _.isArray(b) && _.isArray(a);
const noNeedToCompare = (b, a) => {
if (deepEqual(b, a)) return ["No changes."];
if (nonMatchingArrays(b, a)) return ["Comparing arrays with non-arrays is not allowed."];
if (bothArrays(b, a)) return ["Changed from (" + convertValue(b) + ") to (" + convertValue(a) + ")."];
return null;
};

function processObjects(beforeObjects, afterObjects, root, processMethod) {
let results = [];
let newRoot = createNewRoot(root);

Expand All @@ -73,20 +82,11 @@ function processObjects(beforeObjects, afterObjects, root) {
beforeObjects = _.omit(beforeObjects, deleted);
_.forEach(beforeObjects, (beforeObject, key) => {
let afterObject = _.get(afterObjects, key);
if (afterObject && !deepEqual(beforeObject, afterObject)) results = _.concat(results, process(beforeObject, afterObject, newRoot + key));
if (afterObject && !deepEqual(beforeObject, afterObject)) results = _.concat(results, processMethod(beforeObject, afterObject, newRoot + key));
});
return results;
}

const nonMatchingArrays = (b, a) => (_.isArray(b) && !_.isArray(a)) || (_.isArray(a) && !_.isArray(b));
const bothArrays = (b, a) => _.isArray(b) && _.isArray(a);
const noNeedToCompare = (b, a) => {
if (deepEqual(b, a)) return ["No changes."];
if (nonMatchingArrays(b, a)) return ["Comparing arrays with non-arrays is not allowed."];
if (bothArrays(b, a)) return ["Changed from (" + convertValue(b) + ") to (" + convertValue(a) + ")."];
return null;
};

function process(before, after, root = "") {
let noNeed = noNeedToCompare(before, after);
if (noNeed) return noNeed;
Expand All @@ -105,7 +105,7 @@ function process(before, after, root = "") {
let afterObjects = extractObjects(after);
after = _.omit(after, _.keys(afterObjects));

let objResults = processObjects(beforeObjects, afterObjects, root);
let objResults = processObjects(beforeObjects, afterObjects, root, process);

// Process the rest
let results = [];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-change-description",
"version": "1.0.4",
"version": "1.0.5",
"description": "JSON Auto Change Description",
"homepage": "https://github.com/cope/auto-change-description#readme",
"author": "Predrag Stojadinovic <predrag@stojadinovic.net>",
Expand Down

0 comments on commit db0766c

Please sign in to comment.