Skip to content

Commit

Permalink
feat: add test for nested TemplateLiteral
Browse files Browse the repository at this point in the history
  • Loading branch information
waynzh committed Mar 1, 2024
1 parent 7fc54fe commit 40f2513
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -56,7 +56,9 @@ export default createRule<[], MessageId>({
function isLiteral(expression: TSESTree.Expression): boolean {
return (
expression.type === AST_NODE_TYPES.Literal ||
expression.type === AST_NODE_TYPES.TemplateLiteral
(expression.type === AST_NODE_TYPES.TemplateLiteral &&
expression.expressions.length === 0 &&
expression.quasis.length === 1)
);
}

Expand Down
Expand Up @@ -61,6 +61,11 @@ ruleTester.run('no-useless-template-literals', rule, {
\`\${left}\${center}\${right}\`;
`,

`
declare const num = 1;
\`a\${\`b\${num}\`}c\`;
`,

'`1 + 1 = ${1 + 1}`;',

'`true && false = ${true && false}`;',
Expand Down Expand Up @@ -371,14 +376,27 @@ ruleTester.run('no-useless-template-literals', rule, {
},

{
code: '`a${`b`}`;',
output: '`ab`;',
code: '`a${`${`b`}c`}`;',
output: '`a${`bc`}`;',
errors: [
{
messageId: 'noUselessTemplateLiteral',
line: 1,
column: 8,
endColumn: 11,
},
],
},

{
code: '`a${`bc`}`;',
output: '`abc`;',
errors: [
{
messageId: 'noUselessTemplateLiteral',
line: 1,
column: 5,
endColumn: 8,
endColumn: 9,
},
],
},
Expand Down

0 comments on commit 40f2513

Please sign in to comment.