From a368a12221a4c00b21fd08add3e2bfd9e832e7d2 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Fri, 24 Sep 2021 09:27:02 -0400 Subject: [PATCH] chore(dev-deps): upgrade eslint-plugin-unicorn to v36 https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v36.0.0 --- lib/index.js | 9 +++++---- lib/utils.js | 13 +++++++------ package.json | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/index.js b/lib/index.js index 26e28c50..32e427a6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -43,21 +43,22 @@ function loadRule (ruleName) { } // import all rules in lib/rules -const allRules = fs +const allRules = Object.fromEntries(fs .readdirSync(`${__dirname}/rules`) .filter(fileName => fileName.endsWith('.js') && /^[^._]/.test(fileName)) .map(fileName => fileName.replace(/\.js$/, '')) - .reduce((rules, ruleName) => Object.assign(rules, { [ruleName]: loadRule(ruleName) }), {}); + .map(ruleName => [ruleName, loadRule(ruleName)])); module.exports.rules = allRules; +// eslint-disable-next-line unicorn/prefer-object-from-entries module.exports.configs = Object.keys(configFilters).reduce((configs, configName) => { return Object.assign(configs, { [configName]: { plugins: ['eslint-plugin'], - rules: Object.keys(allRules) + rules: Object.fromEntries(Object.keys(allRules) .filter(ruleName => configFilters[configName](allRules[ruleName])) - .reduce((rules, ruleName) => Object.assign(rules, { [`${PLUGIN_NAME}/${ruleName}`]: 'error' }), {}), + .map(ruleName => [`${PLUGIN_NAME}/${ruleName}`, 'error'])), }, }); }, {}); diff --git a/lib/utils.js b/lib/utils.js index e00aada3..024360bc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -103,6 +103,7 @@ module.exports = { .map(statement => statement.expression) .filter(expression => expression.type === 'AssignmentExpression') .filter(expression => expression.left.type === 'MemberExpression') + // eslint-disable-next-line unicorn/prefer-object-from-entries .reduce((currentExports, node) => { if ( node.left.object.type === 'Identifier' && node.left.object.name === 'module' && @@ -119,6 +120,7 @@ module.exports = { // Check `module.exports = { create: function () {}, meta: {} }` exportsIsFunction = false; + // eslint-disable-next-line unicorn/prefer-object-from-entries return node.right.properties.reduce((parsedProps, prop) => { const keyValue = module.exports.getKeyName(prop); if (INTERESTING_KEYS.has(keyValue)) { @@ -276,6 +278,7 @@ module.exports = { if (reportArgs.length === 1) { if (reportArgs[0].type === 'ObjectExpression') { + // eslint-disable-next-line unicorn/prefer-object-from-entries return reportArgs[0].properties.reduce((reportInfo, property) => { const propName = module.exports.getKeyName(property); @@ -308,9 +311,9 @@ module.exports = { return null; } - return keys + return Object.fromEntries(keys .slice(0, reportArgs.length) - .reduce((reportInfo, key, index) => Object.assign(reportInfo, { [key]: reportArgs[index] }), {}); + .map((key, index) => [key, reportArgs[index]])); }, /** @@ -332,10 +335,8 @@ module.exports = { identifier.parent.parent === identifier.parent.parent.parent.init && identifier.parent.parent.parent.id.type === 'Identifier' ) - .map(identifier => context.getDeclaredVariables(identifier.parent.parent.parent)) - .reduce((allVariables, variablesForIdentifier) => [...allVariables, ...variablesForIdentifier], []) - .map(variable => variable.references) - .reduce((allRefs, refsForVariable) => [...allRefs, ...refsForVariable], []) + .flatMap(identifier => context.getDeclaredVariables(identifier.parent.parent.parent)) + .flatMap(variable => variable.references) .map(ref => ref.identifier)); }, diff --git a/package.json b/package.json index b15172fc..3194399c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "eslint-plugin-markdown": "^2.0.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-self": "^1.2.1", - "eslint-plugin-unicorn": "^31.0.0", + "eslint-plugin-unicorn": "^36.0.0", "eslint-scope": "^5.1.1", "espree": "^7.3.0", "estraverse": "^5.0.0",