]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/template-curly-spacing.md
f0079ee761723e6e23b6ea1aac240caf15829118
[pve-eslint.git] / eslint / docs / src / rules / template-curly-spacing.md
1 ---
2 title: template-curly-spacing
3 layout: doc
4 rule_type: layout
5 ---
6
7
8
9 We can embed expressions in template strings with using a pair of `${` and `}`.
10
11 This rule can force usage of spacing _within_ the curly brace pair according to style guides.
12
13 ```js
14 let hello = `hello, ${people.name}!`;
15 ```
16
17 ## Rule Details
18
19 This rule aims to maintain consistency around the spacing inside of template literals.
20
21 ## Options
22
23 ```json
24 {
25 "template-curly-spacing": ["error", "never"]
26 }
27 ```
28
29 This rule has one option which has either `"never"` or `"always"` as value.
30
31 * `"never"` (by default) - Disallows spaces inside of the curly brace pair.
32 * `"always"` - Requires one or more spaces inside of the curly brace pair.
33
34 ## Examples
35
36 ### never
37
38 Examples of **incorrect** code for this rule with the default `"never"` option:
39
40 ::: incorrect
41
42 ```js
43 /*eslint template-curly-spacing: "error"*/
44
45 `hello, ${ people.name}!`;
46 `hello, ${people.name }!`;
47
48 `hello, ${ people.name }!`;
49 ```
50
51 :::
52
53 Examples of **correct** code for this rule with the default `"never"` option:
54
55 ::: correct
56
57 ```js
58 /*eslint template-curly-spacing: "error"*/
59
60 `hello, ${people.name}!`;
61
62 `hello, ${
63 people.name
64 }!`;
65 ```
66
67 :::
68
69 ### always
70
71 Examples of **incorrect** code for this rule with the `"always"` option:
72
73 ::: incorrect
74
75 ```js
76 /*eslint template-curly-spacing: ["error", "always"]*/
77
78 `hello, ${ people.name}!`;
79 `hello, ${people.name }!`;
80
81 `hello, ${people.name}!`;
82 ```
83
84 :::
85
86 Examples of **correct** code for this rule with the `"always"` option:
87
88 ::: correct
89
90 ```js
91 /*eslint template-curly-spacing: ["error", "always"]*/
92
93 `hello, ${ people.name }!`;
94
95 `hello, ${
96 people.name
97 }!`;
98 ```
99
100 :::
101
102 ## When Not To Use It
103
104 If you don't want to be notified about usage of spacing inside of template strings, then it's safe to disable this rule.