Skip to content

Commit 2b47b7e

Browse files
build(deps-dev): bump eslint-plugin-unicorn from 40.1.0 to 43.0.2 (#302)
* build(deps-dev): bump eslint-plugin-unicorn from 40.1.0 to 43.0.2 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 40.1.0 to 43.0.2. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](sindresorhus/eslint-plugin-unicorn@v40.1.0...v43.0.2) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * chore: autofix eslint-plugin-unicorn lint violations Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bryan Mishkin <[email protected]>
1 parent 90118d2 commit 2b47b7e

File tree

8 files changed

+121
-128
lines changed

8 files changed

+121
-128
lines changed

Diff for: build/generate-readme-table.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const fs = require('fs');
4-
const path = require('path');
3+
const fs = require('node:fs');
4+
const path = require('node:path');
55
const rules = require('..').rules;
66

77
const README_LOCATION = path.resolve(__dirname, '..', 'README.md');

Diff for: lib/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// Requirements
1010
// ------------------------------------------------------------------------------
1111

12-
const fs = require('fs');
13-
const path = require('path');
12+
const fs = require('node:fs');
13+
const path = require('node:path');
1414
const packageMetadata = require('../package');
1515
const PLUGIN_NAME = packageMetadata.name.replace(/^eslint-plugin-/, '');
1616

@@ -43,7 +43,6 @@ const allRules = Object.fromEntries(
4343

4444
module.exports.rules = allRules;
4545

46-
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
4746
module.exports.configs = Object.keys(configFilters).reduce(
4847
(configs, configName) => {
4948
return Object.assign(configs, {

Diff for: lib/rules/require-meta-docs-url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Requirements
99
// -----------------------------------------------------------------------------
1010

11-
const path = require('path');
11+
const path = require('node:path');
1212
const util = require('../utils');
1313
const { getStaticValue } = require('eslint-utils');
1414

Diff for: lib/utils.js

+110-116
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const INTERESTING_RULE_KEYS = new Set(['create', 'meta']);
4141
* @returns Object
4242
*/
4343
function collectInterestingProperties(properties, interestingKeys) {
44-
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
4544
return properties.reduce((parsedProps, prop) => {
4645
const keyValue = module.exports.getKeyName(prop);
4746
if (interestingKeys.has(keyValue)) {
@@ -119,136 +118,132 @@ function isTypeScriptRuleHelper(node) {
119118
* Helper for `getRuleInfo`. Handles ESM and TypeScript rules.
120119
*/
121120
function getRuleExportsESM(ast, scopeManager) {
122-
return (
123-
ast.body
124-
.filter((statement) =>
125-
[
126-
'ExportDefaultDeclaration', // export default rule;
127-
'TSExportAssignment', // export = rule;
128-
].includes(statement.type)
129-
)
130-
.map((statement) => statement.declaration || statement.expression)
131-
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
132-
.reduce((currentExports, node) => {
133-
if (node.type === 'ObjectExpression') {
134-
// Check `export default { create() {}, meta: {} }`
135-
return collectInterestingProperties(
136-
node.properties,
137-
INTERESTING_RULE_KEYS
138-
);
139-
} else if (isFunctionRule(node)) {
140-
// Check `export default function(context) { return { ... }; }`
141-
return { create: node, meta: null, isNewStyle: false };
142-
} else if (isTypeScriptRuleHelper(node)) {
143-
// Check `export default someTypeScriptHelper({ create() {}, meta: {} });
121+
return ast.body
122+
.filter((statement) =>
123+
[
124+
'ExportDefaultDeclaration', // export default rule;
125+
'TSExportAssignment', // export = rule;
126+
].includes(statement.type)
127+
)
128+
.map((statement) => statement.declaration || statement.expression)
129+
130+
.reduce((currentExports, node) => {
131+
if (node.type === 'ObjectExpression') {
132+
// Check `export default { create() {}, meta: {} }`
133+
return collectInterestingProperties(
134+
node.properties,
135+
INTERESTING_RULE_KEYS
136+
);
137+
} else if (isFunctionRule(node)) {
138+
// Check `export default function(context) { return { ... }; }`
139+
return { create: node, meta: null, isNewStyle: false };
140+
} else if (isTypeScriptRuleHelper(node)) {
141+
// Check `export default someTypeScriptHelper({ create() {}, meta: {} });
142+
return collectInterestingProperties(
143+
node.arguments[0].properties,
144+
INTERESTING_RULE_KEYS
145+
);
146+
} else if (node.type === 'Identifier') {
147+
// Rule could be stored in a variable before being exported.
148+
const possibleRule = findVariableValue(node, scopeManager);
149+
if (possibleRule) {
150+
if (possibleRule.type === 'ObjectExpression') {
151+
// Check `const possibleRule = { ... }; export default possibleRule;
152+
return collectInterestingProperties(
153+
possibleRule.properties,
154+
INTERESTING_RULE_KEYS
155+
);
156+
} else if (isFunctionRule(possibleRule)) {
157+
// Check `const possibleRule = function(context) { return { ... } }; export default possibleRule;`
158+
return { create: possibleRule, meta: null, isNewStyle: false };
159+
} else if (isTypeScriptRuleHelper(possibleRule)) {
160+
// Check `const possibleRule = someTypeScriptHelper({ ... }); export default possibleRule;
161+
return collectInterestingProperties(
162+
possibleRule.arguments[0].properties,
163+
INTERESTING_RULE_KEYS
164+
);
165+
}
166+
}
167+
}
168+
return currentExports;
169+
}, {});
170+
}
171+
172+
/**
173+
* Helper for `getRuleInfo`. Handles CJS rules.
174+
*/
175+
function getRuleExportsCJS(ast, scopeManager) {
176+
let exportsVarOverridden = false;
177+
let exportsIsFunction = false;
178+
return ast.body
179+
.filter((statement) => statement.type === 'ExpressionStatement')
180+
.map((statement) => statement.expression)
181+
.filter((expression) => expression.type === 'AssignmentExpression')
182+
.filter((expression) => expression.left.type === 'MemberExpression')
183+
184+
.reduce((currentExports, node) => {
185+
if (
186+
node.left.object.type === 'Identifier' &&
187+
node.left.object.name === 'module' &&
188+
node.left.property.type === 'Identifier' &&
189+
node.left.property.name === 'exports'
190+
) {
191+
exportsVarOverridden = true;
192+
if (isFunctionRule(node.right)) {
193+
// Check `module.exports = function (context) { return { ... }; }`
194+
195+
exportsIsFunction = true;
196+
return { create: node.right, meta: null, isNewStyle: false };
197+
} else if (node.right.type === 'ObjectExpression') {
198+
// Check `module.exports = { create: function () {}, meta: {} }`
199+
144200
return collectInterestingProperties(
145-
node.arguments[0].properties,
201+
node.right.properties,
146202
INTERESTING_RULE_KEYS
147203
);
148-
} else if (node.type === 'Identifier') {
204+
} else if (node.right.type === 'Identifier') {
149205
// Rule could be stored in a variable before being exported.
150-
const possibleRule = findVariableValue(node, scopeManager);
206+
const possibleRule = findVariableValue(node.right, scopeManager);
151207
if (possibleRule) {
152208
if (possibleRule.type === 'ObjectExpression') {
153-
// Check `const possibleRule = { ... }; export default possibleRule;
209+
// Check `const possibleRule = { ... }; module.exports = possibleRule;
154210
return collectInterestingProperties(
155211
possibleRule.properties,
156212
INTERESTING_RULE_KEYS
157213
);
158214
} else if (isFunctionRule(possibleRule)) {
159-
// Check `const possibleRule = function(context) { return { ... } }; export default possibleRule;`
215+
// Check `const possibleRule = function(context) { return { ... } }; module.exports = possibleRule;`
160216
return { create: possibleRule, meta: null, isNewStyle: false };
161-
} else if (isTypeScriptRuleHelper(possibleRule)) {
162-
// Check `const possibleRule = someTypeScriptHelper({ ... }); export default possibleRule;
163-
return collectInterestingProperties(
164-
possibleRule.arguments[0].properties,
165-
INTERESTING_RULE_KEYS
166-
);
167217
}
168218
}
169219
}
170-
return currentExports;
171-
}, {})
172-
);
173-
}
174-
175-
/**
176-
* Helper for `getRuleInfo`. Handles CJS rules.
177-
*/
178-
function getRuleExportsCJS(ast, scopeManager) {
179-
let exportsVarOverridden = false;
180-
let exportsIsFunction = false;
181-
return (
182-
ast.body
183-
.filter((statement) => statement.type === 'ExpressionStatement')
184-
.map((statement) => statement.expression)
185-
.filter((expression) => expression.type === 'AssignmentExpression')
186-
.filter((expression) => expression.left.type === 'MemberExpression')
187-
// eslint-disable-next-line unicorn/prefer-object-from-entries -- this is fine for now
188-
.reduce((currentExports, node) => {
189-
if (
190-
node.left.object.type === 'Identifier' &&
191-
node.left.object.name === 'module' &&
192-
node.left.property.type === 'Identifier' &&
193-
node.left.property.name === 'exports'
194-
) {
195-
exportsVarOverridden = true;
196-
if (isFunctionRule(node.right)) {
197-
// Check `module.exports = function (context) { return { ... }; }`
198-
199-
exportsIsFunction = true;
200-
return { create: node.right, meta: null, isNewStyle: false };
201-
} else if (node.right.type === 'ObjectExpression') {
202-
// Check `module.exports = { create: function () {}, meta: {} }`
220+
return {};
221+
} else if (
222+
!exportsIsFunction &&
223+
node.left.object.type === 'MemberExpression' &&
224+
node.left.object.object.type === 'Identifier' &&
225+
node.left.object.object.name === 'module' &&
226+
node.left.object.property.type === 'Identifier' &&
227+
node.left.object.property.name === 'exports' &&
228+
node.left.property.type === 'Identifier' &&
229+
INTERESTING_RULE_KEYS.has(node.left.property.name)
230+
) {
231+
// Check `module.exports.create = () => {}`
232+
233+
currentExports[node.left.property.name] = node.right;
234+
} else if (
235+
!exportsVarOverridden &&
236+
node.left.object.type === 'Identifier' &&
237+
node.left.object.name === 'exports' &&
238+
node.left.property.type === 'Identifier' &&
239+
INTERESTING_RULE_KEYS.has(node.left.property.name)
240+
) {
241+
// Check `exports.create = () => {}`
203242

204-
return collectInterestingProperties(
205-
node.right.properties,
206-
INTERESTING_RULE_KEYS
207-
);
208-
} else if (node.right.type === 'Identifier') {
209-
// Rule could be stored in a variable before being exported.
210-
const possibleRule = findVariableValue(node.right, scopeManager);
211-
if (possibleRule) {
212-
if (possibleRule.type === 'ObjectExpression') {
213-
// Check `const possibleRule = { ... }; module.exports = possibleRule;
214-
return collectInterestingProperties(
215-
possibleRule.properties,
216-
INTERESTING_RULE_KEYS
217-
);
218-
} else if (isFunctionRule(possibleRule)) {
219-
// Check `const possibleRule = function(context) { return { ... } }; module.exports = possibleRule;`
220-
return { create: possibleRule, meta: null, isNewStyle: false };
221-
}
222-
}
223-
}
224-
return {};
225-
} else if (
226-
!exportsIsFunction &&
227-
node.left.object.type === 'MemberExpression' &&
228-
node.left.object.object.type === 'Identifier' &&
229-
node.left.object.object.name === 'module' &&
230-
node.left.object.property.type === 'Identifier' &&
231-
node.left.object.property.name === 'exports' &&
232-
node.left.property.type === 'Identifier' &&
233-
INTERESTING_RULE_KEYS.has(node.left.property.name)
234-
) {
235-
// Check `module.exports.create = () => {}`
236-
237-
currentExports[node.left.property.name] = node.right;
238-
} else if (
239-
!exportsVarOverridden &&
240-
node.left.object.type === 'Identifier' &&
241-
node.left.object.name === 'exports' &&
242-
node.left.property.type === 'Identifier' &&
243-
INTERESTING_RULE_KEYS.has(node.left.property.name)
244-
) {
245-
// Check `exports.create = () => {}`
246-
247-
currentExports[node.left.property.name] = node.right;
248-
}
249-
return currentExports;
250-
}, {})
251-
);
243+
currentExports[node.left.property.name] = node.right;
244+
}
245+
return currentExports;
246+
}, {});
252247
}
253248

254249
/**
@@ -600,7 +595,6 @@ module.exports = {
600595

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

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"eslint-plugin-markdown": "^3.0.0",
6060
"eslint-plugin-node": "^11.1.0",
6161
"eslint-plugin-prettier": "^4.2.1",
62-
"eslint-plugin-unicorn": "^40.1.0",
62+
"eslint-plugin-unicorn": "^43.0.2",
6363
"eslint-scope": "^7.1.1",
6464
"espree": "^9.4.0",
6565
"husky": "^8.0.1",

Diff for: tests/build/generate-readme-table.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const fs = require('fs');
4-
const path = require('path');
3+
const fs = require('node:fs');
4+
const path = require('node:path');
55
const assert = require('chai').assert;
66

77
describe('table in README.md', () => {

Diff for: tests/lib/rule-setup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const { readdirSync, readFileSync } = require('fs');
4-
const path = require('path');
3+
const { readdirSync, readFileSync } = require('node:fs');
4+
const path = require('node:path');
55
const assert = require('chai').assert;
66
const plugin = require('../..');
77

Diff for: tests/lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { inspect } = require('util');
3+
const { inspect } = require('node:util');
44
const lodash = require('lodash');
55
const espree = require('espree');
66
const eslintScope = require('eslint-scope');

0 commit comments

Comments
 (0)