Skip to content

Commit d03bcf4

Browse files
committed
fix(no-focused-tests): detect table format uage of .only.each (#489)
* refactor(no-focused-tests): use `isSupportedAccessor` utility function * fix(no-focused-tests): detect table format usage of `.only.each`
1 parent 45c6b3b commit d03bcf4

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/rules/__tests__/no-focused-tests.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ ruleTester.run('no-focused-tests', rule, {
3434
code: 'describe.only.each()',
3535
errors: [{ messageId: 'focusedTest', column: 10, line: 1 }],
3636
},
37+
{
38+
code: 'describe.only.each`table`()',
39+
errors: [{ messageId: 'focusedTest', column: 10, line: 1 }],
40+
},
3741
{
3842
code: 'describe["only"]()',
3943
errors: [{ messageId: 'focusedTest', column: 10, line: 1 }],
@@ -46,6 +50,10 @@ ruleTester.run('no-focused-tests', rule, {
4650
code: 'it.only.each()',
4751
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
4852
},
53+
{
54+
code: 'it.only.each`table`()',
55+
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
56+
},
4957
{
5058
code: 'it["only"]()',
5159
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
@@ -58,6 +66,10 @@ ruleTester.run('no-focused-tests', rule, {
5866
code: 'test.only.each()',
5967
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
6068
},
69+
{
70+
code: 'test.only.each`table`()',
71+
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
72+
},
6173
{
6274
code: 'test["only"]()',
6375
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],

src/rules/no-focused-tests.ts

+12-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import {
22
AST_NODE_TYPES,
33
TSESTree,
44
} from '@typescript-eslint/experimental-utils';
5-
import { DescribeAlias, TestCaseName, createRule } from './utils';
5+
import {
6+
DescribeAlias,
7+
TestCaseName,
8+
createRule,
9+
isSupportedAccessor,
10+
} from './utils';
611

712
const testFunctions = new Set<string>([
813
DescribeAlias.describe,
@@ -17,14 +22,9 @@ const matchesTestFunction = (object: TSESTree.LeftHandSideExpression) =>
1722
const isCallToFocusedTestFunction = (object: TSESTree.Identifier) =>
1823
object.name.startsWith('f') && testFunctions.has(object.name.substring(1));
1924

20-
const isPropertyNamedOnly = (
21-
property: TSESTree.Expression | TSESTree.Identifier,
22-
) =>
23-
('name' in property && property.name === 'only') ||
24-
('value' in property && property.value === 'only');
25-
2625
const isCallToTestOnlyFunction = (callee: TSESTree.MemberExpression) =>
27-
matchesTestFunction(callee.object) && isPropertyNamedOnly(callee.property);
26+
matchesTestFunction(callee.object) &&
27+
isSupportedAccessor(callee.property, 'only');
2828

2929
export default createRule({
3030
name: __filename,
@@ -44,7 +44,10 @@ export default createRule({
4444
defaultOptions: [],
4545
create: context => ({
4646
CallExpression(node) {
47-
const { callee } = node;
47+
const callee =
48+
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
49+
? node.callee.tag
50+
: node.callee;
4851

4952
if (callee.type === AST_NODE_TYPES.MemberExpression) {
5053
if (
@@ -78,16 +81,6 @@ export default createRule({
7881
) {
7982
context.report({ messageId: 'focusedTest', node: callee });
8083
}
81-
82-
if (
83-
callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
84-
callee.tag.type === AST_NODE_TYPES.MemberExpression &&
85-
callee.tag.object &&
86-
callee.tag.object.type === AST_NODE_TYPES.Identifier &&
87-
isCallToFocusedTestFunction(callee.tag.object)
88-
) {
89-
context.report({ messageId: 'focusedTest', node: callee });
90-
}
9184
},
9285
}),
9386
});

0 commit comments

Comments
 (0)