Skip to content

Commit 7e86a8a

Browse files
authored
Add more test cases for prefer-string-raw rule (#2690)
1 parent 7c2c1ff commit 7e86a8a

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

test/prefer-string-raw.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ test.snapshot({
3434
String.raw`import {} from "foo" with {"key\\key": "value"}`,
3535
String.raw`export {} from "foo" with {key: "value\\value"}`,
3636
String.raw`export {} from "foo" with {"key\\key": "value"}`,
37+
String.raw`a = '\\'`,
38+
String.raw`a = 'a\\b\"'`,
3739
],
3840
invalid: [
3941
String.raw`a = 'a\\b'`,
4042
String.raw`a = {['a\\b']: b}`,
4143
String.raw`function a() {return'a\\b'}`,
4244
String.raw`const foo = "foo \\x46";`,
45+
String.raw`a = 'a\\b\''`,
46+
String.raw`a = "a\\b\""`,
4347
],
4448
});
4549

test/snapshots/prefer-string-raw.js.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,45 @@ Generated by [AVA](https://avajs.dev).
8787
> 1 | const foo = "foo \\\\x46";␊
8888
| ^^^^^^^^^^^ \`String.raw\` should be used to avoid escaping \`\\\`.␊
8989
`
90+
91+
## invalid(5): a = 'a\\b\''
92+
93+
> Input
94+
95+
`␊
96+
1 | a = 'a\\\\b\\''␊
97+
`
98+
99+
> Output
100+
101+
`␊
102+
1 | a = String.raw\`a\\b'\`␊
103+
`
104+
105+
> Error 1/1
106+
107+
`␊
108+
> 1 | a = 'a\\\\b\\''␊
109+
| ^^^^^^^^ \`String.raw\` should be used to avoid escaping \`\\\`.␊
110+
`
111+
112+
## invalid(6): a = "a\\b\""
113+
114+
> Input
115+
116+
`␊
117+
1 | a = "a\\\\b\\""␊
118+
`
119+
120+
> Output
121+
122+
`␊
123+
1 | a = String.raw\`a\\b"\`␊
124+
`
125+
126+
> Error 1/1
127+
128+
`␊
129+
> 1 | a = "a\\\\b\\""␊
130+
| ^^^^^^^^ \`String.raw\` should be used to avoid escaping \`\\\`.␊
131+
`
68 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)