Skip to content

Commit

Permalink
fix: not use lodash.merge
Browse files Browse the repository at this point in the history
  • Loading branch information
yutak23 committed Nov 6, 2024
1 parent 6b05df8 commit 0a39885
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 34 additions & 29 deletions test/lib/rule-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
}
}
},
Expand Down Expand Up @@ -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);
}
}
},
Expand Down

0 comments on commit 0a39885

Please sign in to comment.