Skip to content

Commit 9c083eb

Browse files
authored
Merge pull request #289 from lo1tuma/identical
Improve performance of no-identical-title
2 parents eca5b6c + 6cd1c3c commit 9c083eb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/rules/no-identical-title.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ function newLayer() {
1010
}
1111

1212
function isFirstArgLiteral(node) {
13-
return node.arguments && node.arguments[0] && node.arguments[0].type === 'Literal';
13+
return (
14+
node.arguments &&
15+
node.arguments[0] &&
16+
node.arguments[0].type === 'Literal'
17+
);
1418
}
1519

1620
module.exports = {
@@ -22,22 +26,26 @@ module.exports = {
2226
},
2327
create(context) {
2428
const astUtils = createAstUtils(context.settings);
29+
const isTestCase = astUtils.buildIsTestCaseAnswerer();
30+
const isDescribe = astUtils.buildIsDescribeAnswerer();
31+
2532
const titleLayers = [ newLayer() ];
2633

2734
function handlTestCaseTitles(titles, node, title) {
28-
if (astUtils.isTestCase(node)) {
35+
if (isTestCase(node)) {
2936
if (titles.includes(title)) {
3037
context.report({
3138
node,
32-
message: 'Test title is used multiple times in the same test suite.'
39+
message:
40+
'Test title is used multiple times in the same test suite.'
3341
});
3442
}
3543
titles.push(title);
3644
}
3745
}
3846

3947
function handlTestSuiteTitles(titles, node, title) {
40-
if (!astUtils.isDescribe(node)) {
48+
if (!isDescribe(node)) {
4149
return;
4250
}
4351
if (titles.includes(title)) {
@@ -53,7 +61,7 @@ module.exports = {
5361
CallExpression(node) {
5462
const currentLayer = titleLayers[titleLayers.length - 1];
5563

56-
if (astUtils.isDescribe(node)) {
64+
if (isDescribe(node)) {
5765
titleLayers.push(newLayer());
5866
}
5967
if (!isFirstArgLiteral(node)) {
@@ -65,7 +73,7 @@ module.exports = {
6573
handlTestSuiteTitles(currentLayer.describeTitles, node, title);
6674
},
6775
'CallExpression:exit'(node) {
68-
if (astUtils.isDescribe(node)) {
76+
if (isDescribe(node)) {
6977
titleLayers.pop();
7078
}
7179
}

0 commit comments

Comments
 (0)