Skip to content

Commit

Permalink
disable proto null for module exports
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Jul 5, 2023
1 parent db06343 commit 9093d9a
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tools/eslint-rules/set-proto-to-null-in-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
return {
ObjectExpression(node) {
// Not adding __proto__ to module.exports as it will break a lot of libraries
if (isModuleExportsObject(node)) {
if (isModuleExportsObject(node) || isModifiedExports(node)) {
return;
}

Expand Down Expand Up @@ -97,3 +97,42 @@ function isModuleExportsObject(node) {
node.parent.left.property.name === 'exports'
);
}

function isModifiedExports(node) {
return (
node.parent &&
(isObjectAssignCall(node.parent) || isObjectDefinePropertiesCall(node.parent))
);
}

// Helper function to check if the node represents an ObjectAssign call
function isObjectAssignCall(node) {
return (
node.type === 'CallExpression' &&
node.callee &&
node.callee.type === 'Identifier' &&
node.callee.name === 'ObjectAssign' &&
node.arguments.length > 1 &&
node.arguments.some(arg =>
arg.type === 'MemberExpression' &&
arg.object.name === 'module' &&
arg.property.name === 'exports'
)
);
}

// Helper function to check if the node represents an ObjectDefineProperties call
function isObjectDefinePropertiesCall(node) {
return (
node.type === 'CallExpression' &&
node.callee &&
node.callee.type === 'Identifier' &&
node.callee.name === 'ObjectDefineProperties' &&
node.arguments.length > 1 &&
node.arguments.some(arg =>
arg.type === 'MemberExpression' &&
arg.object.name === 'module' &&
arg.property.name === 'exports'
)
);
}

0 comments on commit 9093d9a

Please sign in to comment.