Skip to content

Commit 9093d9a

Browse files
committed
disable proto null for module exports
1 parent db06343 commit 9093d9a

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tools/eslint-rules/set-proto-to-null-in-object.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
return {
1212
ObjectExpression(node) {
1313
// Not adding __proto__ to module.exports as it will break a lot of libraries
14-
if (isModuleExportsObject(node)) {
14+
if (isModuleExportsObject(node) || isModifiedExports(node)) {
1515
return;
1616
}
1717

@@ -97,3 +97,42 @@ function isModuleExportsObject(node) {
9797
node.parent.left.property.name === 'exports'
9898
);
9999
}
100+
101+
function isModifiedExports(node) {
102+
return (
103+
node.parent &&
104+
(isObjectAssignCall(node.parent) || isObjectDefinePropertiesCall(node.parent))
105+
);
106+
}
107+
108+
// Helper function to check if the node represents an ObjectAssign call
109+
function isObjectAssignCall(node) {
110+
return (
111+
node.type === 'CallExpression' &&
112+
node.callee &&
113+
node.callee.type === 'Identifier' &&
114+
node.callee.name === 'ObjectAssign' &&
115+
node.arguments.length > 1 &&
116+
node.arguments.some(arg =>
117+
arg.type === 'MemberExpression' &&
118+
arg.object.name === 'module' &&
119+
arg.property.name === 'exports'
120+
)
121+
);
122+
}
123+
124+
// Helper function to check if the node represents an ObjectDefineProperties call
125+
function isObjectDefinePropertiesCall(node) {
126+
return (
127+
node.type === 'CallExpression' &&
128+
node.callee &&
129+
node.callee.type === 'Identifier' &&
130+
node.callee.name === 'ObjectDefineProperties' &&
131+
node.arguments.length > 1 &&
132+
node.arguments.some(arg =>
133+
arg.type === 'MemberExpression' &&
134+
arg.object.name === 'module' &&
135+
arg.property.name === 'exports'
136+
)
137+
);
138+
}

0 commit comments

Comments
 (0)