Skip to content

Commit

Permalink
Use lodash.mergewith instead of deep-assign (#251)
Browse files Browse the repository at this point in the history
Fixes #241.
  • Loading branch information
kevva authored and sindresorhus committed Sep 22, 2017
1 parent ed0ee48 commit 4f4de13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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: {},
Expand All @@ -96,10 +103,11 @@ const emptyOptions = () => ({
});

const buildConfig = opts => {
const config = deepAssign(
const config = mergeWith(
emptyOptions(),
DEFAULT_CONFIG,
opts
opts,
mergeFn
);

if (opts.space) {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 4f4de13

Please sign in to comment.