Skip to content

Commit b27c80d

Browse files
committed
fix: prefer hasOwnProperty over in
Fixes #334
1 parent 7f1867b commit b27c80d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/rules/__tests__/valid-describe.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ ruleTester.run('valid-describe', rule, {
3838
test('bar', () => {})
3939
)
4040
`,
41+
`
42+
if (hasOwnProperty(obj, key)) {
43+
}
44+
`,
4145
],
4246
invalid: [
4347
{

src/rules/tsUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const isHook = (
166166
): node is JestFunctionCallExpressionWithIdentifierCallee<HookName> => {
167167
return (
168168
node.callee.type === AST_NODE_TYPES.Identifier &&
169-
node.callee.name in HookName
169+
HookName.hasOwnProperty(node.callee.name)
170170
);
171171
};
172172

@@ -175,10 +175,10 @@ export const isTestCase = (
175175
): node is JestFunctionCallExpression<TestCaseName> => {
176176
return (
177177
(node.callee.type === AST_NODE_TYPES.Identifier &&
178-
node.callee.name in TestCaseName) ||
178+
TestCaseName.hasOwnProperty(node.callee.name)) ||
179179
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
180180
node.callee.object.type === AST_NODE_TYPES.Identifier &&
181-
node.callee.object.name in TestCaseName)
181+
TestCaseName.hasOwnProperty(node.callee.object.name))
182182
);
183183
};
184184

@@ -187,10 +187,10 @@ export const isDescribe = (
187187
): node is JestFunctionCallExpression<DescribeAlias> => {
188188
return (
189189
(node.callee.type === AST_NODE_TYPES.Identifier &&
190-
node.callee.name in DescribeAlias) ||
190+
DescribeAlias.hasOwnProperty(node.callee.name)) ||
191191
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
192192
node.callee.object.type === AST_NODE_TYPES.Identifier &&
193-
node.callee.object.name in DescribeAlias)
193+
DescribeAlias.hasOwnProperty(node.callee.object.name))
194194
);
195195
};
196196

0 commit comments

Comments
 (0)