diff --git a/package.json b/package.json index a7804b8..0fdf020 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "ghooks": "^2.0.4", "globals": "^15.9.0", "in-publish": "^2.0.1", - "lodash.merge": "^4.6.2", "mocha": "^3.5.3", "npm-run-all": "^4.1.5", "nyc": "^11.9.0", diff --git a/test/lib/rule-finder.js b/test/lib/rule-finder.js index 5f0d42e..5345c43 100644 --- a/test/lib/rule-finder.js +++ b/test/lib/rule-finder.js @@ -4,13 +4,40 @@ const assert = require('assert'); const proxyquire = require('proxyquire'); const { builtinRules } = require('eslint/use-at-your-own-risk'); const semver = require('semver'); -const merge = require('lodash.merge'); const { ESLint } = require('eslint'); const processCwd = process.cwd; const isV8Eslint = ESLint.configType === 'eslintrc'; const eslintVersion = isV8Eslint ? 'prior-v8' : 'post-v8'; +const isObject = (item) => { + return item && typeof item === 'object' && !Array.isArray(item); +}; + +const deepMerge = (target, source) => { + if (!isObject(target)) { + target = {}; + } + if (!isObject(source)) { + return target; + } + + Object.keys(source).forEach(key => { + const sourceValue = source[key]; + const targetValue = target[key]; + + if (Array.isArray(sourceValue)) { + target[key] = Array.isArray(targetValue) ? targetValue.concat(sourceValue) : sourceValue.slice(); + } else if (isObject(sourceValue)) { + target[key] = isObject(targetValue) ? deepMerge(targetValue, sourceValue) : deepMerge({}, sourceValue); + } else { + target[key] = sourceValue; + } + }); + + return target; +}; + const mockCreateRequire = (getExport, plugins, relative) => { // Use the mocked require. const moduleRequire = (id) => { @@ -215,27 +242,16 @@ const getRuleFinder = isV8Eslint calculateConfigForFile(filePath) { const mergedConfig = {}; defaultConfig.forEach(config => { - merge(mergedConfig, config); + deepMerge(mergedConfig, config); }); - if(!specifiedFileRelative) { - if (Array.isArray(config)) { - config.forEach(config => { - merge(mergedConfig, config); - }); - return mergedConfig; - } else { - return merge(mergedConfig, config); - } - } - if (Array.isArray(config)) { config.forEach(config => { - merge(mergedConfig, config); + deepMerge(mergedConfig, config); }); return mergedConfig; } else { - return merge(mergedConfig, config); + return deepMerge(mergedConfig, config); } } }, @@ -294,27 +310,16 @@ const getRuleFinderForDedupeTests = isV8Eslint calculateConfigForFile(filePath) { const mergedConfig = {}; defaultConfig.forEach(config => { - merge(mergedConfig, config); + deepMerge(mergedConfig, config); }); - if(!specifiedFileRelative) { - if (Array.isArray(config)) { - config.forEach(config => { - merge(mergedConfig, config); - }); - return mergedConfig; - } else { - return merge(mergedConfig, config); - } - } - if (Array.isArray(config)) { config.forEach(config => { - merge(mergedConfig, config); + deepMerge(mergedConfig, config); }); return mergedConfig; } else { - return merge(mergedConfig, config); + return deepMerge(mergedConfig, config); } } },