Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ module.exports = {
'node-core/no-unescaped-regexp-dot': 'error',
'node-core/no-duplicate-requires': 'error',
'node-core/prefer-proto': 'error',
'node-core/set-proto-to-null-in-object': 'error',
},
globals: {
ByteLengthQueuingStrategy: 'readable',
Expand Down
31 changes: 31 additions & 0 deletions tools/eslint-rules/set-proto-to-null-in-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

module.exports = {
meta: {
messages: {
error: 'Add `__proto__: null` to object',
},
},
create: function(context) {
return {
ObjectExpression(node) {
const properties = node.properties;
let hasProto = false;

for (const property of properties) {
if (property.key && property.key.name === '__proto__') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify that the value is null?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and I'm gonna make it fixable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasProto = true;
break;
}
}

if (!hasProto) {
context.report({
node,
message: 'Every object must have __proto__: null',
});
}
},
};
},
};