Skip to content

Commit

Permalink
fix(valid-title): ignore string addition
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 28, 2019
1 parent a7b91f7 commit 5337caa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rules/__tests__/valid-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ruleTester = new TSESLint.RuleTester({
ruleTester.run('title-must-be-string', rule, {
valid: [
'it("is a string", () => {});',
'it("is" + " a " + " string", () => {});',
'test("is a string", () => {});',
'xtest("is a string", () => {});',
'xtest(`${myFunc} is a string`, () => {});',
Expand Down
21 changes: 21 additions & 0 deletions src/rules/valid-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ import {
const trimFXprefix = (word: string) =>
['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;

const doesBinaryExpressionContainStringNode = (
binaryExp: TSESTree.BinaryExpression,
): boolean => {
if (isStringNode(binaryExp.right)) {
return true;
}

if (binaryExp.left.type === AST_NODE_TYPES.BinaryExpression) {
return doesBinaryExpressionContainStringNode(binaryExp.left);
}

return isStringNode(binaryExp.left);
};

export default createRule({
name: __filename,
meta: {
Expand Down Expand Up @@ -56,6 +70,13 @@ export default createRule({
const [argument] = node.arguments;

if (!isStringNode(argument)) {
if (
argument.type === AST_NODE_TYPES.BinaryExpression &&
doesBinaryExpressionContainStringNode(argument)
) {
return;
}

if (
argument.type !== AST_NODE_TYPES.TemplateLiteral &&
!(ignoreTypeOfDescribeName && isDescribe(node))
Expand Down

0 comments on commit 5337caa

Please sign in to comment.