Skip to content

Commit

Permalink
fix: use lodash.merge and delete the commented code0
Browse files Browse the repository at this point in the history
  • Loading branch information
yutak23 committed Nov 6, 2024
1 parent aff89ab commit 959ca30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 44 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"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
52 changes: 8 additions & 44 deletions test/lib/rule-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,13 @@ 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 All @@ -63,17 +36,8 @@ const defaultConfig = [
plugins: {
"@": {
languages: {
js: null // require("../languages/js")
js: null
},
// rules: new Proxy({}, {
// get(target, property) {
// return Rules.get(property);
// },

// has(target, property) {
// return Rules.has(property);
// }
// })
rules: Object.keys(builtinRules).map((ruleId) => {
return { [ruleId]: ruleId() };
})
Expand Down Expand Up @@ -242,12 +206,12 @@ const getRuleFinder = isV8Eslint
calculateConfigForFile(filePath) {
const mergedConfig = {};
defaultConfig.forEach(config => {
deepMerge(mergedConfig, config);
merge(mergedConfig, config);
});

return Array.isArray(config)
? config.reduce((acc, cfg) => deepMerge(acc, cfg), mergedConfig)
: deepMerge(mergedConfig, config)
? config.reduce((acc, cfg) => merge(acc, cfg), mergedConfig)
: merge(mergedConfig, config)
}
},
},
Expand Down Expand Up @@ -304,12 +268,12 @@ const getRuleFinderForDedupeTests = isV8Eslint
calculateConfigForFile(filePath) {
const mergedConfig = {};
defaultConfig.forEach(config => {
deepMerge(mergedConfig, config);
merge(mergedConfig, config);
});

return Array.isArray(config)
? config.reduce((acc, cfg) => deepMerge(acc, cfg), mergedConfig)
: deepMerge(mergedConfig, config)
? config.reduce((acc, cfg) => merge(acc, cfg), mergedConfig)
: merge(mergedConfig, config)
}
},
},
Expand Down

0 comments on commit 959ca30

Please sign in to comment.