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

feat: remove dependencies for Node built-ins #3847

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 3 additions & 11 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2022,
"ecmaFeatures": {
"jsx": true
},
Expand All @@ -34,17 +34,10 @@
"consistent-return": 0,

"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
"prefer-object-spread": 0, // until node 8 is required
"prefer-rest-params": 0, // until node 6 is required
"prefer-spread": 0, // until node 6 is required
"function-call-argument-newline": 1, // TODO: enable
"function-call-argument-newline": 1,
"function-paren-newline": 0,
"no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
"no-param-reassign": 1,
"no-restricted-syntax": [2, {
"selector": "ObjectPattern",
"message": "Object destructuring is not compatible with Node v4"
}],
"strict": [2, "safe"],
"valid-jsdoc": [2, {
"requireReturn": false,
Expand Down Expand Up @@ -73,12 +66,11 @@
{
"files": ".github/workflows/*.js",
"parserOptions": {
"ecmaVersion": 2019,
"ecmaVersion": 2022,
},
"rules": {
"camelcase": 0,
"no-console": 0,
"no-restricted-syntax": 0,
},
},
],
Expand Down
117 changes: 0 additions & 117 deletions .github/workflows/node-minors.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/node-18+.yml → .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Tests: node.js (18+)'
name: 'Tests: node.js'

on: [pull_request, push]

Expand All @@ -14,7 +14,7 @@ jobs:
with:
versionsAsRoot: true
type: majors
preset: '>=18'
preset: '^18.18.0 || ^20.9.0 || >=21.1.0'

latest:
needs: [matrix]
Expand Down
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
'use strict';

const fromEntries = require('object.fromentries');
const entries = require('object.entries');

const allRules = require('./lib/rules');

function filterRules(rules, predicate) {
return fromEntries(entries(rules).filter((entry) => predicate(entry[1])));
return Object.fromEntries(Object.entries(rules).filter((entry) => predicate(entry[1])));
}

/**
* @param {object} rules - rules object mapping rule name to rule module
* @returns {Record<string, 2 | 'error'>}
*/
function configureAsError(rules) {
return fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
return Object.fromEntries(Object.keys(rules).map((key) => [`react/${key}`, 2]));
}

/** @type {Partial<typeof allRules>} */
Expand Down
24 changes: 9 additions & 15 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@

'use strict';

const flatMap = require('array.prototype.flatmap');
const values = require('object.values');

const Components = require('../util/Components');
const propsUtil = require('../util/props');
const astUtil = require('../util/ast');
const docsUrl = require('../util/docsUrl');
const propWrapperUtil = require('../util/propWrapper');
const report = require('../util/report');
const eslintUtil = require('../util/eslint');

const getSourceCode = eslintUtil.getSourceCode;
const getText = eslintUtil.getText;
const { getSourceCode, getText } = require('../util/eslint');

/**
* Checks if prop is nested
Expand Down Expand Up @@ -260,7 +254,7 @@ module.exports = {
}

const annotationTypeArguments = propsUtil.getTypeArguments(
component.node.parent.id.typeAnnotation.typeAnnotation
component.node.parent.id.typeAnnotation.typeAnnotation,
);
if (
annotationTypeArguments && (
Expand All @@ -269,7 +263,7 @@ module.exports = {
)
) {
return annotationTypeArguments.params.find(
(param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
(param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation',
);
}
}
Expand All @@ -278,7 +272,7 @@ module.exports = {
if (node.type === 'TSTypeLiteral' || node.type === 'ObjectTypeAnnotation' || node.type === 'TSInterfaceBody') {
const currentNode = [].concat(
objectTypeAnnotations.get(identifier.name) || [],
node
node,
);
objectTypeAnnotations.set(identifier.name, currentNode);
} else if (
Expand Down Expand Up @@ -317,7 +311,7 @@ module.exports = {
&& astUtil.isCallExpression(node.value)
&& propWrapperUtil.isPropWrapperFunction(
context,
getText(context, node.value.callee)
getText(context, node.value.callee),
)
) {
checkPropWrapperArguments(node, node.value.arguments);
Expand All @@ -343,7 +337,7 @@ module.exports = {
astUtil.isCallExpression(right)
&& propWrapperUtil.isPropWrapperFunction(
context,
getText(context, right.callee)
getText(context, right.callee),
)
) {
checkPropWrapperArguments(component.node, right.arguments);
Expand Down Expand Up @@ -384,7 +378,7 @@ module.exports = {
return;
}

values(components.list()).forEach((component) => {
Object.values(components.list()).forEach((component) => {
const annotation = getComponentTypeAnnotation(component);

if (annotation) {
Expand All @@ -396,7 +390,7 @@ module.exports = {
} else if (annotation.type === 'TSTypeReference') {
propType = objectTypeAnnotations.get(annotation.typeName.name);
} else if (annotation.type === 'TSIntersectionType') {
propType = flatMap(annotation.types, (type) => (
propType = annotation.types.flatMap((type) => (
type.type === 'TSTypeReference'
? objectTypeAnnotations.get(type.typeName.name)
: type
Expand All @@ -407,7 +401,7 @@ module.exports = {
[].concat(propType).filter(Boolean).forEach((prop) => {
validatePropNaming(
component.node,
prop.properties || prop.members || prop.body
prop.properties || prop.members || prop.body,
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/button-has-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
},

create(context) {
const configuration = Object.assign({}, optionDefaults, context.options[0]);
const configuration = { ...optionDefaults, ...context.options[0] };

function reportMissing(node) {
report(context, messages.missingType, 'missingType', {
Expand Down
14 changes: 6 additions & 8 deletions lib/rules/checked-requires-onchange-or-readonly.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'use strict';

const ASTUtils = require('jsx-ast-utils');
const flatMap = require('array.prototype.flatmap');
const isCreateElement = require('../util/isCreateElement');
const report = require('../util/report');
const docsUrl = require('../util/docsUrl');
Expand All @@ -30,14 +29,13 @@ const defaultOptions = {
*/
function extractTargetProps(properties, keyName) {
return new Set(
flatMap(
properties,
properties.flatMap(
(prop) => (
prop[keyName] && targetPropSet.has(prop[keyName].name)
? [prop[keyName].name]
: []
)
)
),
),
);
}

Expand All @@ -64,14 +62,14 @@ module.exports = {
}],
},
create(context) {
const options = Object.assign({}, defaultOptions, context.options[0]);
const options = { ...defaultOptions, ...context.options[0] };

function reportMissingProperty(node) {
report(
context,
messages.missingProperty,
'missingProperty',
{ node }
{ node },
);
}

Expand All @@ -80,7 +78,7 @@ module.exports = {
context,
messages.exclusiveCheckedAttribute,
'exclusiveCheckedAttribute',
{ node }
{ node },
);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/rules/default-props-match-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

'use strict';

const values = require('object.values');

const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const report = require('../util/report');
Expand Down Expand Up @@ -95,12 +93,12 @@ module.exports = {
return {
'Program:exit'() {
// If no defaultProps could be found, we don't report anything.
values(components.list())
Object.values(components.list())
.filter((component) => component.defaultProps)
.forEach((component) => {
reportInvalidDefaultProps(
component.declaredPropTypes,
component.defaultProps || {}
component.defaultProps || {},
);
});
},
Expand Down
Loading
Loading