Skip to content

Commit 5337caa

Browse files
committed
fix(valid-title): ignore string addition
1 parent a7b91f7 commit 5337caa

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/rules/__tests__/valid-title.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const ruleTester = new TSESLint.RuleTester({
1212
ruleTester.run('title-must-be-string', rule, {
1313
valid: [
1414
'it("is a string", () => {});',
15+
'it("is" + " a " + " string", () => {});',
1516
'test("is a string", () => {});',
1617
'xtest("is a string", () => {});',
1718
'xtest(`${myFunc} is a string`, () => {});',

src/rules/valid-title.ts

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ import {
1616
const trimFXprefix = (word: string) =>
1717
['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
1818

19+
const doesBinaryExpressionContainStringNode = (
20+
binaryExp: TSESTree.BinaryExpression,
21+
): boolean => {
22+
if (isStringNode(binaryExp.right)) {
23+
return true;
24+
}
25+
26+
if (binaryExp.left.type === AST_NODE_TYPES.BinaryExpression) {
27+
return doesBinaryExpressionContainStringNode(binaryExp.left);
28+
}
29+
30+
return isStringNode(binaryExp.left);
31+
};
32+
1933
export default createRule({
2034
name: __filename,
2135
meta: {
@@ -56,6 +70,13 @@ export default createRule({
5670
const [argument] = node.arguments;
5771

5872
if (!isStringNode(argument)) {
73+
if (
74+
argument.type === AST_NODE_TYPES.BinaryExpression &&
75+
doesBinaryExpressionContainStringNode(argument)
76+
) {
77+
return;
78+
}
79+
5980
if (
6081
argument.type !== AST_NODE_TYPES.TemplateLiteral &&
6182
!(ignoreTypeOfDescribeName && isDescribe(node))

0 commit comments

Comments
 (0)