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(util): identify only valid global properties #341

Merged
merged 1 commit into from Jul 22, 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
20 changes: 20 additions & 0 deletions src/rules/__tests__/no-identical-title.test.js
Expand Up @@ -113,6 +113,26 @@ ruleTester.run('no-identical-title', rule, {
es6: true,
},
},
{
code: [
'const test = { content: () => "foo" }',
'test.content(`testing backticks with the same title`);',
'test.content(`testing backticks with the same title`);',
].join('\n'),
env: {
es6: true,
},
},
{
code: [
'const describe = { content: () => "foo" }',
'describe.content(`testing backticks with the same title`);',
'describe.content(`testing backticks with the same title`);',
].join('\n'),
env: {
es6: true,
},
},
],

invalid: [
Expand Down
10 changes: 8 additions & 2 deletions src/rules/util.js
Expand Up @@ -101,13 +101,18 @@ const describeAliases = new Set(['describe', 'fdescribe', 'xdescribe']);

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

const describeProperties = new Set(['each', 'only', 'skip']);

const testCaseProperties = new Set(['each', 'only', 'skip', 'todo']);

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

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

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