Skip to content

Commit 5c7ea92

Browse files
authored
new-for-builtins: Ignore Object(x) === x and Object(x) !== x (#944)
1 parent 81b21a5 commit 5c7ea92

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

rules/new-for-builtins.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ const create = context => {
1717
const {callee} = node;
1818
const {name} = callee;
1919

20+
if (
21+
name === 'Object' &&
22+
node.parent &&
23+
node.parent.type === 'BinaryExpression' &&
24+
(node.parent.operator === '===' || node.parent.operator === '!==') &&
25+
(node.parent.left === node || node.parent.right === node)
26+
) {
27+
return;
28+
}
29+
2030
if (enforceNew.has(name) && !isShadowed(context.getScope(), callee)) {
2131
context.report({
2232
node,

test/new-for-builtins.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ test({
108108
`,
109109
// Not builtin
110110
'new Foo();Bar();',
111-
'Foo();new Bar();'
111+
'Foo();new Bar();',
112+
// Ignored
113+
'const isObject = v => Object(v) === v;',
114+
'(x) !== Object(x)'
112115
],
113116
invalid: [
114117
{

0 commit comments

Comments
 (0)