From 4f4de133b3c015387efcc34ab579d54da9bc7e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20M=C3=A5rtensson?= Date: Fri, 22 Sep 2017 07:32:22 +0200 Subject: [PATCH] Use `lodash.mergewith` instead of `deep-assign` (#251) Fixes #241. --- lib/options-manager.js | 20 ++++++++++++++------ package.json | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/options-manager.js b/lib/options-manager.js index e9ac9bec..a486239c 100644 --- a/lib/options-manager.js +++ b/lib/options-manager.js @@ -2,7 +2,7 @@ const os = require('os'); const path = require('path'); const arrify = require('arrify'); -const deepAssign = require('deep-assign'); +const mergeWith = require('lodash.mergewith'); const multimatch = require('multimatch'); const pathExists = require('path-exists'); const pkgConf = require('pkg-conf'); @@ -43,6 +43,13 @@ const DEFAULT_CONFIG = { } }; +// Keep the same behaviour in mergeWith as deepAssign +const mergeFn = (prev, val) => { + if (Array.isArray(prev) && Array.isArray(val)) { + return val; + } +}; + const normalizeOpts = opts => { opts = Object.assign({}, opts); @@ -85,7 +92,7 @@ const mergeWithPkgConf = opts => { return Object.assign({}, conf, opts); }; -// Define the shape of deep properties for deepAssign +// Define the shape of deep properties for mergeWith const emptyOptions = () => ({ rules: {}, settings: {}, @@ -96,10 +103,11 @@ const emptyOptions = () => ({ }); const buildConfig = opts => { - const config = deepAssign( + const config = mergeWith( emptyOptions(), DEFAULT_CONFIG, - opts + opts, + mergeFn ); if (opts.space) { @@ -199,8 +207,8 @@ const findApplicableOverrides = (path, overrides) => { const mergeApplicableOverrides = (baseOptions, applicableOverrides) => { applicableOverrides = applicableOverrides.map(normalizeOpts); - const overrides = [emptyOptions(), baseOptions].concat(applicableOverrides); - return deepAssign.apply(null, overrides); + const overrides = [emptyOptions(), baseOptions].concat(applicableOverrides, mergeFn); + return mergeWith.apply(null, overrides); }; // Creates grouped sets of merged options together with the paths they apply to. diff --git a/package.json b/package.json index 31009b00..c30da2d3 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "dependencies": { "arrify": "^1.0.0", "debug": "^2.2.0", - "deep-assign": "^1.0.0", "eslint": "^3.18.0", "eslint-config-xo": "^0.18.0", "eslint-formatter-pretty": "^1.0.0", @@ -86,6 +85,7 @@ "has-flag": "^2.0.0", "ignore": "^3.2.6", "lodash.isequal": "^4.4.0", + "lodash.mergewith": "^4.6.0", "meow": "^3.4.2", "multimatch": "^2.1.0", "open-editor": "^1.0.1",