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

adjust js guard behavior #317

Merged
merged 2 commits into from Jul 20, 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
5 changes: 2 additions & 3 deletions src/rules/no-if.js
@@ -1,10 +1,9 @@
import { getDocsUrl, getNodeName, isTestCase, testCaseNames } from './util';
import { getDocsUrl, isTestCase } from './util';

const isTestArrowFunction = node =>
node !== undefined &&
node.type === 'ArrowFunctionExpression' &&
node.parent.type === 'CallExpression' &&
testCaseNames.has(getNodeName(node.parent.callee));
isTestCase(node.parent);

export default {
meta: {
Expand Down
34 changes: 13 additions & 21 deletions src/rules/util.js
Expand Up @@ -77,25 +77,9 @@ export const argument = node =>
export const argument2 = node =>
node.parent.parent.parent.arguments && node.parent.parent.parent.arguments[0];

const describeAliases = new Set([
'describe',
'describe.only',
'describe.skip',
'fdescribe',
'xdescribe',
]);
const describeAliases = new Set(['describe', 'fdescribe', 'xdescribe']);

export const testCaseNames = new Set([
'fit',
'it',
'it.only',
'it.skip',
'test',
'test.only',
'test.skip',
'xit',
'xtest',
]);
const testCaseNames = new Set(['fit', 'it', 'test', 'xit', 'xtest']);

const testHookNames = new Set([
'beforeAll',
Expand Down Expand Up @@ -127,17 +111,25 @@ export const getNodeName = node => {
export const isHook = node =>
node &&
node.type === 'CallExpression' &&
testHookNames.has(getNodeName(node.callee));
node.callee.type === 'Identifier' &&
testHookNames.has(node.callee.name);

export const isTestCase = node =>
node &&
node.type === 'CallExpression' &&
testCaseNames.has(getNodeName(node.callee));
((node.callee.type === 'Identifier' && testCaseNames.has(node.callee.name)) ||
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
testCaseNames.has(node.callee.object.name)));

export const isDescribe = node =>
node &&
node.type === 'CallExpression' &&
describeAliases.has(getNodeName(node.callee));
((node.callee.type === 'Identifier' &&
describeAliases.has(node.callee.name)) ||
(node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
describeAliases.has(node.callee.object.name)));

export const isFunction = node =>
node &&
Expand Down