Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tsutils): identify only valid global properties #343

Merged
merged 1 commit into from Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/rules/tsUtils.ts
Expand Up @@ -96,6 +96,19 @@ export enum HookName {
'afterEach' = 'afterEach',
}

export enum DescribeProperty {
Copy link
Member

Choose a reason for hiding this comment

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

no need to export them, but meh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I've just tried to be consistent with all of the rest, but you are right, it is not necessary at the moment.

'each' = 'each',
'only' = 'only',
'skip' = 'skip',
}

export enum TestCaseProperty {
'each' = 'each',
'only' = 'only',
'skip' = 'skip',
'todo' = 'todo',
}

export type JestFunctionName = DescribeAlias | TestCaseName | HookName;

export interface JestFunctionIdentifier<FunctionName extends JestFunctionName>
Expand Down Expand Up @@ -178,7 +191,9 @@ export const isTestCase = (
TestCaseName.hasOwnProperty(node.callee.name)) ||
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
node.callee.object.type === AST_NODE_TYPES.Identifier &&
TestCaseName.hasOwnProperty(node.callee.object.name))
TestCaseName.hasOwnProperty(node.callee.object.name) &&
node.callee.property.type === AST_NODE_TYPES.Identifier &&
TestCaseProperty.hasOwnProperty(node.callee.property.name))
);
};

Expand All @@ -190,7 +205,9 @@ export const isDescribe = (
DescribeAlias.hasOwnProperty(node.callee.name)) ||
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
node.callee.object.type === AST_NODE_TYPES.Identifier &&
DescribeAlias.hasOwnProperty(node.callee.object.name))
DescribeAlias.hasOwnProperty(node.callee.object.name) &&
node.callee.property.type === AST_NODE_TYPES.Identifier &&
DescribeProperty.hasOwnProperty(node.callee.property.name))
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/rules/util.js
Expand Up @@ -112,6 +112,7 @@ export const isTestCase = node =>
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
testCaseNames.has(node.callee.object.name) &&
node.callee.property.type === 'Identifier' &&
testCaseProperties.has(node.callee.property.name)));

export const isDescribe = node =>
Expand All @@ -122,6 +123,7 @@ export const isDescribe = node =>
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
describeAliases.has(node.callee.object.name) &&
node.callee.property.type === 'Identifier' &&
describeProperties.has(node.callee.property.name)));

export const isFunction = node =>
Expand Down