Skip to content

build(deps-dev): bump eslint-plugin-unicorn from 40.1.0 to 43.0.2 #302

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

Merged
merged 2 commits into from
Sep 13, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/generate-readme-table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const rules = require('..').rules;

const README_LOCATION = path.resolve(__dirname, '..', 'README.md');
Expand Down
5 changes: 2 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
// ------------------------------------------------------------------------------

const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const packageMetadata = require('../package');
const PLUGIN_NAME = packageMetadata.name.replace(/^eslint-plugin-/, '');

Expand Down Expand Up @@ -43,7 +43,6 @@ const allRules = Object.fromEntries(

module.exports.rules = allRules;

// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
module.exports.configs = Object.keys(configFilters).reduce(
(configs, configName) => {
return Object.assign(configs, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-docs-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Requirements
// -----------------------------------------------------------------------------

const path = require('path');
const path = require('node:path');
const util = require('../utils');
const { getStaticValue } = require('eslint-utils');

Expand Down
226 changes: 110 additions & 116 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const INTERESTING_RULE_KEYS = new Set(['create', 'meta']);
* @returns Object
*/
function collectInterestingProperties(properties, interestingKeys) {
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
return properties.reduce((parsedProps, prop) => {
const keyValue = module.exports.getKeyName(prop);
if (interestingKeys.has(keyValue)) {
Expand Down Expand Up @@ -119,136 +118,132 @@ function isTypeScriptRuleHelper(node) {
* Helper for `getRuleInfo`. Handles ESM and TypeScript rules.
*/
function getRuleExportsESM(ast, scopeManager) {
return (
ast.body
.filter((statement) =>
[
'ExportDefaultDeclaration', // export default rule;
'TSExportAssignment', // export = rule;
].includes(statement.type)
)
.map((statement) => statement.declaration || statement.expression)
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
.reduce((currentExports, node) => {
if (node.type === 'ObjectExpression') {
// Check `export default { create() {}, meta: {} }`
return collectInterestingProperties(
node.properties,
INTERESTING_RULE_KEYS
);
} else if (isFunctionRule(node)) {
// Check `export default function(context) { return { ... }; }`
return { create: node, meta: null, isNewStyle: false };
} else if (isTypeScriptRuleHelper(node)) {
// Check `export default someTypeScriptHelper({ create() {}, meta: {} });
return ast.body
.filter((statement) =>
[
'ExportDefaultDeclaration', // export default rule;
'TSExportAssignment', // export = rule;
].includes(statement.type)
)
.map((statement) => statement.declaration || statement.expression)

.reduce((currentExports, node) => {
if (node.type === 'ObjectExpression') {
// Check `export default { create() {}, meta: {} }`
return collectInterestingProperties(
node.properties,
INTERESTING_RULE_KEYS
);
} else if (isFunctionRule(node)) {
// Check `export default function(context) { return { ... }; }`
return { create: node, meta: null, isNewStyle: false };
} else if (isTypeScriptRuleHelper(node)) {
// Check `export default someTypeScriptHelper({ create() {}, meta: {} });
return collectInterestingProperties(
node.arguments[0].properties,
INTERESTING_RULE_KEYS
);
} else if (node.type === 'Identifier') {
// Rule could be stored in a variable before being exported.
const possibleRule = findVariableValue(node, scopeManager);
if (possibleRule) {
if (possibleRule.type === 'ObjectExpression') {
// Check `const possibleRule = { ... }; export default possibleRule;
return collectInterestingProperties(
possibleRule.properties,
INTERESTING_RULE_KEYS
);
} else if (isFunctionRule(possibleRule)) {
// Check `const possibleRule = function(context) { return { ... } }; export default possibleRule;`
return { create: possibleRule, meta: null, isNewStyle: false };
} else if (isTypeScriptRuleHelper(possibleRule)) {
// Check `const possibleRule = someTypeScriptHelper({ ... }); export default possibleRule;
return collectInterestingProperties(
possibleRule.arguments[0].properties,
INTERESTING_RULE_KEYS
);
}
}
}
return currentExports;
}, {});
}

/**
* Helper for `getRuleInfo`. Handles CJS rules.
*/
function getRuleExportsCJS(ast, scopeManager) {
let exportsVarOverridden = false;
let exportsIsFunction = false;
return ast.body
.filter((statement) => statement.type === 'ExpressionStatement')
.map((statement) => statement.expression)
.filter((expression) => expression.type === 'AssignmentExpression')
.filter((expression) => expression.left.type === 'MemberExpression')

.reduce((currentExports, node) => {
if (
node.left.object.type === 'Identifier' &&
node.left.object.name === 'module' &&
node.left.property.type === 'Identifier' &&
node.left.property.name === 'exports'
) {
exportsVarOverridden = true;
if (isFunctionRule(node.right)) {
// Check `module.exports = function (context) { return { ... }; }`

exportsIsFunction = true;
return { create: node.right, meta: null, isNewStyle: false };
} else if (node.right.type === 'ObjectExpression') {
// Check `module.exports = { create: function () {}, meta: {} }`

return collectInterestingProperties(
node.arguments[0].properties,
node.right.properties,
INTERESTING_RULE_KEYS
);
} else if (node.type === 'Identifier') {
} else if (node.right.type === 'Identifier') {
// Rule could be stored in a variable before being exported.
const possibleRule = findVariableValue(node, scopeManager);
const possibleRule = findVariableValue(node.right, scopeManager);
if (possibleRule) {
if (possibleRule.type === 'ObjectExpression') {
// Check `const possibleRule = { ... }; export default possibleRule;
// Check `const possibleRule = { ... }; module.exports = possibleRule;
return collectInterestingProperties(
possibleRule.properties,
INTERESTING_RULE_KEYS
);
} else if (isFunctionRule(possibleRule)) {
// Check `const possibleRule = function(context) { return { ... } }; export default possibleRule;`
// Check `const possibleRule = function(context) { return { ... } }; module.exports = possibleRule;`
return { create: possibleRule, meta: null, isNewStyle: false };
} else if (isTypeScriptRuleHelper(possibleRule)) {
// Check `const possibleRule = someTypeScriptHelper({ ... }); export default possibleRule;
return collectInterestingProperties(
possibleRule.arguments[0].properties,
INTERESTING_RULE_KEYS
);
}
}
}
return currentExports;
}, {})
);
}

/**
* Helper for `getRuleInfo`. Handles CJS rules.
*/
function getRuleExportsCJS(ast, scopeManager) {
let exportsVarOverridden = false;
let exportsIsFunction = false;
return (
ast.body
.filter((statement) => statement.type === 'ExpressionStatement')
.map((statement) => statement.expression)
.filter((expression) => expression.type === 'AssignmentExpression')
.filter((expression) => expression.left.type === 'MemberExpression')
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
.reduce((currentExports, node) => {
if (
node.left.object.type === 'Identifier' &&
node.left.object.name === 'module' &&
node.left.property.type === 'Identifier' &&
node.left.property.name === 'exports'
) {
exportsVarOverridden = true;
if (isFunctionRule(node.right)) {
// Check `module.exports = function (context) { return { ... }; }`

exportsIsFunction = true;
return { create: node.right, meta: null, isNewStyle: false };
} else if (node.right.type === 'ObjectExpression') {
// Check `module.exports = { create: function () {}, meta: {} }`
return {};
} else if (
!exportsIsFunction &&
node.left.object.type === 'MemberExpression' &&
node.left.object.object.type === 'Identifier' &&
node.left.object.object.name === 'module' &&
node.left.object.property.type === 'Identifier' &&
node.left.object.property.name === 'exports' &&
node.left.property.type === 'Identifier' &&
INTERESTING_RULE_KEYS.has(node.left.property.name)
) {
// Check `module.exports.create = () => {}`

currentExports[node.left.property.name] = node.right;
} else if (
!exportsVarOverridden &&
node.left.object.type === 'Identifier' &&
node.left.object.name === 'exports' &&
node.left.property.type === 'Identifier' &&
INTERESTING_RULE_KEYS.has(node.left.property.name)
) {
// Check `exports.create = () => {}`

return collectInterestingProperties(
node.right.properties,
INTERESTING_RULE_KEYS
);
} else if (node.right.type === 'Identifier') {
// Rule could be stored in a variable before being exported.
const possibleRule = findVariableValue(node.right, scopeManager);
if (possibleRule) {
if (possibleRule.type === 'ObjectExpression') {
// Check `const possibleRule = { ... }; module.exports = possibleRule;
return collectInterestingProperties(
possibleRule.properties,
INTERESTING_RULE_KEYS
);
} else if (isFunctionRule(possibleRule)) {
// Check `const possibleRule = function(context) { return { ... } }; module.exports = possibleRule;`
return { create: possibleRule, meta: null, isNewStyle: false };
}
}
}
return {};
} else if (
!exportsIsFunction &&
node.left.object.type === 'MemberExpression' &&
node.left.object.object.type === 'Identifier' &&
node.left.object.object.name === 'module' &&
node.left.object.property.type === 'Identifier' &&
node.left.object.property.name === 'exports' &&
node.left.property.type === 'Identifier' &&
INTERESTING_RULE_KEYS.has(node.left.property.name)
) {
// Check `module.exports.create = () => {}`

currentExports[node.left.property.name] = node.right;
} else if (
!exportsVarOverridden &&
node.left.object.type === 'Identifier' &&
node.left.object.name === 'exports' &&
node.left.property.type === 'Identifier' &&
INTERESTING_RULE_KEYS.has(node.left.property.name)
) {
// Check `exports.create = () => {}`

currentExports[node.left.property.name] = node.right;
}
return currentExports;
}, {})
);
currentExports[node.left.property.name] = node.right;
}
return currentExports;
}, {});
}

/**
Expand Down Expand Up @@ -600,7 +595,6 @@ module.exports = {

if (reportArgs.length === 1) {
if (reportArgs[0].type === 'ObjectExpression') {
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
return reportArgs[0].properties.reduce((reportInfo, property) => {
const propName = module.exports.getKeyName(property);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unicorn": "^40.1.0",
"eslint-plugin-unicorn": "^43.0.2",
"eslint-scope": "^7.1.1",
"espree": "^9.4.0",
"husky": "^8.0.1",
Expand Down
4 changes: 2 additions & 2 deletions tests/build/generate-readme-table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const assert = require('chai').assert;

describe('table in README.md', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rule-setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { readdirSync, readFileSync } = require('fs');
const path = require('path');
const { readdirSync, readFileSync } = require('node:fs');
const path = require('node:path');
const assert = require('chai').assert;
const plugin = require('../..');

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { inspect } = require('util');
const { inspect } = require('node:util');
const lodash = require('lodash');
const espree = require('espree');
const eslintScope = require('eslint-scope');
Expand Down