Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Upgrade eslint-plugin-unicorn to v36 #187

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/index.js
Expand Up @@ -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'])),
},
});
}, {});
13 changes: 7 additions & 6 deletions lib/utils.js
Expand Up @@ -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' &&
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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]]));
},

/**
Expand All @@ -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));
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down