Skip to content

Commit 664c6e7

Browse files
committed
feat: remove dependencies for Node built-ins
1 parent b39cecf commit 664c6e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+127
-270
lines changed

index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
'use strict';
22

3-
const fromEntries = require('object.fromentries');
4-
const entries = require('object.entries');
5-
63
const allRules = require('./lib/rules');
74

85
function filterRules(rules, predicate) {
9-
return fromEntries(entries(rules).filter((entry) => predicate(entry[1])));
6+
return Object.fromEntries(Object.entries(rules).filter((entry) => predicate(entry[1])));
107
}
118

129
/**
1310
* @param {object} rules - rules object mapping rule name to rule module
1411
* @returns {Record<string, SEVERITY_ERROR | 'error'>}
1512
*/
1613
function configureAsError(rules) {
17-
return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
14+
return Object.fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
1815
}
1916

2017
/** @type {Partial<typeof allRules>} */

lib/rules/boolean-prop-naming.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@
55

66
'use strict';
77

8-
const flatMap = require('array.prototype.flatmap');
9-
const values = require('object.values');
10-
118
const Components = require('../util/Components');
129
const propsUtil = require('../util/props');
1310
const astUtil = require('../util/ast');
1411
const docsUrl = require('../util/docsUrl');
1512
const propWrapperUtil = require('../util/propWrapper');
1613
const report = require('../util/report');
17-
const eslintUtil = require('../util/eslint');
18-
19-
const getSourceCode = eslintUtil.getSourceCode;
20-
const getText = eslintUtil.getText;
14+
const { getSourceCode, getText } = require('../util/eslint');
2115

2216
/**
2317
* Checks if prop is nested
@@ -384,7 +378,7 @@ module.exports = {
384378
return;
385379
}
386380

387-
values(components.list()).forEach((component) => {
381+
Object.values(components.list()).forEach((component) => {
388382
const annotation = getComponentTypeAnnotation(component);
389383

390384
if (annotation) {
@@ -396,7 +390,7 @@ module.exports = {
396390
} else if (annotation.type === 'TSTypeReference') {
397391
propType = objectTypeAnnotations.get(annotation.typeName.name);
398392
} else if (annotation.type === 'TSIntersectionType') {
399-
propType = flatMap(annotation.types, (type) => (
393+
propType = annotation.types.flatMap((type) => (
400394
type.type === 'TSTypeReference'
401395
? objectTypeAnnotations.get(type.typeName.name)
402396
: type

lib/rules/checked-requires-onchange-or-readonly.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
'use strict';
77

88
const ASTUtils = require('jsx-ast-utils');
9-
const flatMap = require('array.prototype.flatmap');
109
const isCreateElement = require('../util/isCreateElement');
1110
const report = require('../util/report');
1211
const docsUrl = require('../util/docsUrl');
@@ -30,8 +29,7 @@ const defaultOptions = {
3029
*/
3130
function extractTargetProps(properties, keyName) {
3231
return new Set(
33-
flatMap(
34-
properties,
32+
properties.flatMap(
3533
(prop) => (
3634
prop[keyName] && targetPropSet.has(prop[keyName].name)
3735
? [prop[keyName].name]

lib/rules/default-props-match-prop-types.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
'use strict';
88

9-
const values = require('object.values');
10-
119
const Components = require('../util/Components');
1210
const docsUrl = require('../util/docsUrl');
1311
const report = require('../util/report');
@@ -95,7 +93,7 @@ module.exports = {
9593
return {
9694
'Program:exit'() {
9795
// If no defaultProps could be found, we don't report anything.
98-
values(components.list())
96+
Object.values(components.list())
9997
.filter((component) => component.defaultProps)
10098
.forEach((component) => {
10199
reportInvalidDefaultProps(

lib/rules/display-name.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
'use strict';
77

8-
const values = require('object.values');
98
const filter = require('es-iterator-helpers/Iterator.prototype.filter');
109
const forEach = require('es-iterator-helpers/Iterator.prototype.forEach');
1110

@@ -269,7 +268,7 @@ module.exports = {
269268
'Program:exit'() {
270269
const list = components.list();
271270
// Report missing display name for all components
272-
values(list).filter((component) => !component.hasDisplayName).forEach((component) => {
271+
Object.values(list).filter((component) => !component.hasDisplayName).forEach((component) => {
273272
reportMissingDisplayName(component);
274273
});
275274
if (checkContextObjects) {

lib/rules/forbid-elements.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
'use strict';
77

8-
const has = require('hasown');
98
const docsUrl = require('../util/docsUrl');
10-
const getText = require('../util/eslint').getText;
9+
const { getText } = require('../util/eslint');
1110
const isCreateElement = require('../util/isCreateElement');
1211
const report = require('../util/report');
1312

@@ -73,7 +72,7 @@ module.exports = {
7372
});
7473

7574
function reportIfForbidden(element, node) {
76-
if (has(indexedForbidConfigs, element)) {
75+
if (Object.hasOwn(indexedForbidConfigs, element)) {
7776
const message = indexedForbidConfigs[element].message;
7877

7978
report(

lib/rules/function-component-definition.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
'use strict';
77

8-
const arrayIncludes = require('array-includes');
98
const Components = require('../util/Components');
109
const docsUrl = require('../util/docsUrl');
1110
const reportC = require('../util/report');
12-
const getText = require('../util/eslint').getText;
11+
const { getText } = require('../util/eslint');
1312
const propsUtil = require('../util/props');
1413

1514
// ------------------------------------------------------------------------------
@@ -230,7 +229,7 @@ module.exports = {
230229

231230
if (node.parent && node.parent.type === 'Property') return;
232231

233-
if (hasName(node) && !arrayIncludes(namedConfig, functionType)) {
232+
if (hasName(node) && !namedConfig.includes(functionType)) {
234233
report(node, {
235234
messageId: namedConfig[0],
236235
fixerOptions: {
@@ -243,7 +242,7 @@ module.exports = {
243242
},
244243
});
245244
}
246-
if (!hasName(node) && !arrayIncludes(unnamedConfig, functionType)) {
245+
if (!hasName(node) && !unnamedConfig.includes(functionType)) {
247246
report(node, {
248247
messageId: unnamedConfig[0],
249248
fixerOptions: {

lib/rules/jsx-closing-bracket-location.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66
'use strict';
77

8-
const has = require('hasown');
9-
const repeat = require('string.prototype.repeat');
10-
118
const docsUrl = require('../util/docsUrl');
12-
const getSourceCode = require('../util/eslint').getSourceCode;
9+
const { getSourceCode } = require('../util/eslint');
1310
const report = require('../util/report');
1411

1512
// ------------------------------------------------------------------------------
@@ -84,16 +81,16 @@ module.exports = {
8481
options.selfClosing = config;
8582
} else if (typeof config === 'object') {
8683
// [1, {location: 'something'}] (back-compat)
87-
if (has(config, 'location')) {
84+
if (Object.hasOwn(config, 'location')) {
8885
options.nonEmpty = config.location;
8986
options.selfClosing = config.location;
9087
}
9188
// [1, {nonEmpty: 'something'}]
92-
if (has(config, 'nonEmpty')) {
89+
if (Object.hasOwn(config, 'nonEmpty')) {
9390
options.nonEmpty = config.nonEmpty;
9491
}
9592
// [1, {selfClosing: 'something'}]
96-
if (has(config, 'selfClosing')) {
93+
if (Object.hasOwn(config, 'selfClosing')) {
9794
options.selfClosing = config.selfClosing;
9895
}
9996
}
@@ -185,7 +182,7 @@ module.exports = {
185182
}
186183
if (indentation.length + 1 < newColumn) {
187184
// Non-whitespace characters were included in the column offset
188-
spaces = repeat(' ', +correctColumn - indentation.length);
185+
spaces = ' '.repeat(+correctColumn - indentation.length);
189186
}
190187
return indentation + spaces;
191188
}

lib/rules/jsx-closing-tag-location.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55

66
'use strict';
77

8-
const repeat = require('string.prototype.repeat');
9-
const has = require('hasown');
10-
118
const astUtil = require('../util/ast');
129
const docsUrl = require('../util/docsUrl');
13-
const getSourceCode = require('../util/eslint').getSourceCode;
10+
const { getSourceCode } = require('../util/eslint');
1411
const report = require('../util/report');
1512

1613
// ------------------------------------------------------------------------------
@@ -66,7 +63,7 @@ module.exports = {
6663
if (typeof config === 'string') {
6764
option = config;
6865
} else if (typeof config === 'object') {
69-
if (has(config, 'location')) {
66+
if (Object.hasOwn(config, 'location')) {
7067
option = config.location;
7168
}
7269
}
@@ -117,8 +114,7 @@ module.exports = {
117114
node,
118115
loc: node.loc,
119116
fix(fixer) {
120-
const indent = repeat(
121-
' ',
117+
const indent = ' '.repeat(
122118
getIndentation(openingStartOfLine, opening),
123119
);
124120

lib/rules/jsx-curly-brace-presence.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@
66

77
'use strict';
88

9-
const arrayIncludes = require('array-includes');
10-
119
const docsUrl = require('../util/docsUrl');
1210
const jsxUtil = require('../util/jsx');
1311
const report = require('../util/report');
14-
const eslintUtil = require('../util/eslint');
15-
16-
const getSourceCode = eslintUtil.getSourceCode;
17-
const getText = eslintUtil.getText;
12+
const { getSourceCode, getText } = require('../util/eslint');
1813

1914
// ------------------------------------------------------------------------------
2015
// Constants
@@ -38,7 +33,7 @@ function containsLineTerminators(rawStringValue) {
3833
}
3934

4035
function containsBackslash(rawStringValue) {
41-
return arrayIncludes(rawStringValue, '\\');
36+
return rawStringValue.includes('\\');
4237
}
4338

4439
function containsHTMLEntity(rawStringValue) {
@@ -335,7 +330,7 @@ module.exports = {
335330
const childrenExcludingWhitespaceLiteral = children.filter((child) => !isWhiteSpaceLiteral(child));
336331
const adjSiblings = getAdjacentSiblings(node, childrenExcludingWhitespaceLiteral);
337332

338-
return adjSiblings.some((x) => x.type && arrayIncludes(['JSXExpressionContainer', 'JSXElement'], x.type));
333+
return adjSiblings.some((x) => x.type && ['JSXExpressionContainer', 'JSXElement'].includes(x.type));
339334
}
340335
function shouldCheckForUnnecessaryCurly(node, config) {
341336
const parent = node.parent;

0 commit comments

Comments
 (0)