Skip to content

Commit 62b3a4f

Browse files
authored
test(eslint-plugin-template): add test cases for prefer-template-literal reported issues (#2460)
1 parent 95c6964 commit 62b3a4f

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

packages/eslint-plugin-template/docs/rules/prefer-template-literal.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,60 @@ The rule does not have any configuration options.
18421842
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18431843
```
18441844

1845+
<br>
1846+
1847+
---
1848+
1849+
<br>
1850+
1851+
#### Default Config
1852+
1853+
```json
1854+
{
1855+
"rules": {
1856+
"@angular-eslint/template/prefer-template-literal": [
1857+
"error"
1858+
]
1859+
}
1860+
}
1861+
```
1862+
1863+
<br>
1864+
1865+
#### ❌ Invalid Code
1866+
1867+
```html
1868+
<a [href]="'https://example.com/very-long-url-path-that-is-quite-long' + variable">Test</a>
1869+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1870+
```
1871+
1872+
<br>
1873+
1874+
---
1875+
1876+
<br>
1877+
1878+
#### Default Config
1879+
1880+
```json
1881+
{
1882+
"rules": {
1883+
"@angular-eslint/template/prefer-template-literal": [
1884+
"error"
1885+
]
1886+
}
1887+
}
1888+
```
1889+
1890+
<br>
1891+
1892+
#### ❌ Invalid Code
1893+
1894+
```html
1895+
<a [href]="'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + example">Test</a>
1896+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1897+
```
1898+
18451899
</details>
18461900

18471901
<br>

packages/eslint-plugin-template/tests/rules/prefer-template-literal/cases.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,54 @@ export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [
892892
893893
`,
894894
}),
895+
896+
// Test cases for reported bugs
897+
898+
// Bug 1: Simple long string test case
899+
convertAnnotatedSourceToFailureCase({
900+
messageId,
901+
description: 'should fix concatenation with long URL string',
902+
annotatedSource: `
903+
<a [href]="'https://example.com/very-long-url-path-that-is-quite-long' + variable">Test</a>
904+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
905+
`,
906+
annotatedOutput: `
907+
<a [href]="\`https://example.com/very-long-url-path-that-is-quite-long\${variable}\`">Test</a>
908+
909+
`,
910+
}),
911+
912+
// Test cases for specific reported bugs that currently fail
913+
914+
// Test case 1: Add a simple case with the actual failing 108-character string
915+
convertAnnotatedSourceToFailureCase({
916+
messageId,
917+
description: 'should fix exactly 108 char string (reproduces bug)',
918+
annotatedSource: `
919+
<a [href]="'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + example">Test</a>
920+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
921+
`,
922+
annotatedOutput: `
923+
<a [href]="\`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\${example}\`">Test</a>
924+
925+
`,
926+
}),
927+
928+
// Test case demonstrating multiple autofix passes for chained concatenations
929+
// convertAnnotatedSourceToFailureCase({
930+
// messageId,
931+
// description:
932+
// 'should handle chained concatenations of literals requiring multiple autofix passes',
933+
// annotatedSource: `
934+
// {{ 'first' + 'second' + 'third' }}
935+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936+
// `,
937+
// annotatedOutputs: [
938+
// // TODO: this is where we should end up for this source, but what should the interim fixes be?
939+
// `
940+
// {{ 'firstsecondthird' }}
941+
942+
// `,
943+
// ],
944+
// }),
895945
];

0 commit comments

Comments
 (0)