Skip to content

Commit

Permalink
fix: prefer hasOwnProperty over in
Browse files Browse the repository at this point in the history
Fixes #334
  • Loading branch information
SimenB committed Jul 22, 2019
1 parent 7f1867b commit b27c80d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/rules/__tests__/valid-describe.test.ts
Expand Up @@ -38,6 +38,10 @@ ruleTester.run('valid-describe', rule, {
test('bar', () => {})
)
`,
`
if (hasOwnProperty(obj, key)) {
}
`,
],
invalid: [
{
Expand Down
10 changes: 5 additions & 5 deletions src/rules/tsUtils.ts
Expand Up @@ -166,7 +166,7 @@ export const isHook = (
): node is JestFunctionCallExpressionWithIdentifierCallee<HookName> => {
return (
node.callee.type === AST_NODE_TYPES.Identifier &&
node.callee.name in HookName
HookName.hasOwnProperty(node.callee.name)
);
};

Expand All @@ -175,10 +175,10 @@ export const isTestCase = (
): node is JestFunctionCallExpression<TestCaseName> => {
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))
);
};

Expand All @@ -187,10 +187,10 @@ export const isDescribe = (
): node is JestFunctionCallExpression<DescribeAlias> => {
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))
);
};

Expand Down

1 comment on commit b27c80d

@SimenB
Copy link
Member Author

@SimenB SimenB commented on b27c80d Jul 22, 2019

Choose a reason for hiding this comment

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

@G-Rath FYI. Maybe a new Set<DescribeAlias>(Object.keys(DescribeAlias)) or something makes sense?

Please sign in to comment.