/
no-template-literals.js
88 lines (86 loc) · 2.5 KB
/
no-template-literals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const RuleTester = require("../../tester")
const rule = require("../../../lib/rules/no-template-literals.js")
new RuleTester().run("no-template-literals", rule, {
valid: [
"'foo'",
'"bar"',
`
const a1 = "foo"
const a2 = "foo"+bar+"baz"
`,
],
invalid: [
{
code: "`foo`",
output: '"foo"',
errors: ["ES2015 template literals are forbidden."],
},
{
code: "tag`foo`",
output: null,
errors: ["ES2015 template literals are forbidden."],
},
{
//eslint-disable-next-line no-template-curly-in-string
code: "`foo${a}bar${b}baz`",
output: '"foo"+a+"bar"+b+"baz"',
errors: ["ES2015 template literals are forbidden."],
},
{
code: `
const a1 = \`foo\`
const a2 = \`foo\${bar}baz\`
const a3 = tag\`foo\`
`,
output: `
const a1 = "foo"
const a2 = "foo"+bar+"baz"
const a3 = tag\`foo\`
`,
errors: [
"ES2015 template literals are forbidden.",
"ES2015 template literals are forbidden.",
"ES2015 template literals are forbidden.",
],
},
{
//eslint-disable-next-line no-template-curly-in-string
code: "`${a}${b}`",
output: '""+a+b',
errors: ["ES2015 template literals are forbidden."],
},
{
code: "``",
output: '""',
errors: ["ES2015 template literals are forbidden."],
},
{
//eslint-disable-next-line no-template-curly-in-string
code: '`${""}`',
output: '""',
errors: ["ES2015 template literals are forbidden."],
},
{
//eslint-disable-next-line no-template-curly-in-string
code: "`${''}`",
output: "''",
errors: ["ES2015 template literals are forbidden."],
},
{
code: "`\n\t '\"\\`\\$\\${`",
output: '"\\n\\t \'\\"`$${"',
errors: ["ES2015 template literals are forbidden."],
},
{
//eslint-disable-next-line no-template-curly-in-string
code: "`${'abc'}`",
output: "'abc'",
errors: ["ES2015 template literals are forbidden."],
},
],
})