From b27c80d9aba8d68d158414350db9b1047dbabf52 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 22 Jul 2019 18:05:39 +0200 Subject: [PATCH] fix: prefer `hasOwnProperty` over `in` Fixes #334 --- src/rules/__tests__/valid-describe.test.ts | 4 ++++ src/rules/tsUtils.ts | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rules/__tests__/valid-describe.test.ts b/src/rules/__tests__/valid-describe.test.ts index b5e2cd76e..66e299e55 100644 --- a/src/rules/__tests__/valid-describe.test.ts +++ b/src/rules/__tests__/valid-describe.test.ts @@ -38,6 +38,10 @@ ruleTester.run('valid-describe', rule, { test('bar', () => {}) ) `, + ` + if (hasOwnProperty(obj, key)) { + } + `, ], invalid: [ { diff --git a/src/rules/tsUtils.ts b/src/rules/tsUtils.ts index 5f28d7141..95f3c642c 100644 --- a/src/rules/tsUtils.ts +++ b/src/rules/tsUtils.ts @@ -166,7 +166,7 @@ export const isHook = ( ): node is JestFunctionCallExpressionWithIdentifierCallee => { return ( node.callee.type === AST_NODE_TYPES.Identifier && - node.callee.name in HookName + HookName.hasOwnProperty(node.callee.name) ); }; @@ -175,10 +175,10 @@ export const isTestCase = ( ): node is JestFunctionCallExpression => { return ( (node.callee.type === AST_NODE_TYPES.Identifier && - node.callee.name in TestCaseName) || + TestCaseName.hasOwnProperty(node.callee.name)) || (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && - node.callee.object.name in TestCaseName) + TestCaseName.hasOwnProperty(node.callee.object.name)) ); }; @@ -187,10 +187,10 @@ export const isDescribe = ( ): node is JestFunctionCallExpression => { return ( (node.callee.type === AST_NODE_TYPES.Identifier && - node.callee.name in DescribeAlias) || + DescribeAlias.hasOwnProperty(node.callee.name)) || (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && - node.callee.object.name in DescribeAlias) + DescribeAlias.hasOwnProperty(node.callee.object.name)) ); };