Skip to content

Commit ae3e599

Browse files
ranyitzSimenB
authored andcommitted
fix(tsutils): identify only valid global properties (#343)
1 parent 8e67740 commit ae3e599

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/rules/tsUtils.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ export enum HookName {
9696
'afterEach' = 'afterEach',
9797
}
9898

99+
export enum DescribeProperty {
100+
'each' = 'each',
101+
'only' = 'only',
102+
'skip' = 'skip',
103+
}
104+
105+
export enum TestCaseProperty {
106+
'each' = 'each',
107+
'only' = 'only',
108+
'skip' = 'skip',
109+
'todo' = 'todo',
110+
}
111+
99112
export type JestFunctionName = DescribeAlias | TestCaseName | HookName;
100113

101114
export interface JestFunctionIdentifier<FunctionName extends JestFunctionName>
@@ -178,7 +191,9 @@ export const isTestCase = (
178191
TestCaseName.hasOwnProperty(node.callee.name)) ||
179192
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
180193
node.callee.object.type === AST_NODE_TYPES.Identifier &&
181-
TestCaseName.hasOwnProperty(node.callee.object.name))
194+
TestCaseName.hasOwnProperty(node.callee.object.name) &&
195+
node.callee.property.type === AST_NODE_TYPES.Identifier &&
196+
TestCaseProperty.hasOwnProperty(node.callee.property.name))
182197
);
183198
};
184199

@@ -190,7 +205,9 @@ export const isDescribe = (
190205
DescribeAlias.hasOwnProperty(node.callee.name)) ||
191206
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
192207
node.callee.object.type === AST_NODE_TYPES.Identifier &&
193-
DescribeAlias.hasOwnProperty(node.callee.object.name))
208+
DescribeAlias.hasOwnProperty(node.callee.object.name) &&
209+
node.callee.property.type === AST_NODE_TYPES.Identifier &&
210+
DescribeProperty.hasOwnProperty(node.callee.property.name))
194211
);
195212
};
196213

src/rules/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const isTestCase = node =>
112112
(node.callee.type === 'MemberExpression' &&
113113
node.callee.object.type === 'Identifier' &&
114114
testCaseNames.has(node.callee.object.name) &&
115+
node.callee.property.type === 'Identifier' &&
115116
testCaseProperties.has(node.callee.property.name)));
116117

117118
export const isDescribe = node =>
@@ -122,6 +123,7 @@ export const isDescribe = node =>
122123
(node.callee.type === 'MemberExpression' &&
123124
node.callee.object.type === 'Identifier' &&
124125
describeAliases.has(node.callee.object.name) &&
126+
node.callee.property.type === 'Identifier' &&
125127
describeProperties.has(node.callee.property.name)));
126128

127129
export const isFunction = node =>

0 commit comments

Comments
 (0)