Skip to content

Commit

Permalink
new-for-builtins: Ignore Object(x) === x and Object(x) !== x (#944
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fisker committed Dec 21, 2020
1 parent 81b21a5 commit 5c7ea92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions rules/new-for-builtins.js
Expand Up @@ -17,6 +17,16 @@ const create = context => {
const {callee} = node;
const {name} = callee;

if (
name === 'Object' &&
node.parent &&
node.parent.type === 'BinaryExpression' &&
(node.parent.operator === '===' || node.parent.operator === '!==') &&
(node.parent.left === node || node.parent.right === node)
) {
return;
}

if (enforceNew.has(name) && !isShadowed(context.getScope(), callee)) {
context.report({
node,
Expand Down
5 changes: 4 additions & 1 deletion test/new-for-builtins.js
Expand Up @@ -108,7 +108,10 @@ test({
`,
// Not builtin
'new Foo();Bar();',
'Foo();new Bar();'
'Foo();new Bar();',
// Ignored
'const isObject = v => Object(v) === v;',
'(x) !== Object(x)'
],
invalid: [
{
Expand Down

0 comments on commit 5c7ea92

Please sign in to comment.