]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/template-tag-spacing.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / template-tag-spacing.md
CommitLineData
eb39fafa
DC
1# Require or disallow spacing between template tags and their literals (template-tag-spacing)
2
3With ES6, it's possible to create functions called [tagged template literals](#further-reading) where the function parameters consist of a template literal's strings and expressions.
4
5When using tagged template literals, it's possible to insert whitespace between the tag function and the template literal. Since this whitespace is optional, the following lines are equivalent:
6
7```js
8let hello = func`Hello world`;
9let hello = func `Hello world`;
10```
11
12## Rule Details
13
14This rule aims to maintain consistency around the spacing between template tag functions and their template literals.
15
16## Options
17
18```json
19{
20 "template-tag-spacing": ["error", "never"]
21}
22```
23
24This rule has one option whose value can be set to `"never"` or `"always"`
25
26* `"never"` (default) - Disallows spaces between a tag function and its template literal.
27* `"always"` - Requires one or more spaces between a tag function and its template literal.
28
29## Examples
30
31### never
32
33Examples of **incorrect** code for this rule with the default `"never"` option:
34
35```js
36/*eslint template-tag-spacing: "error"*/
37
38func `Hello world`;
39```
40
41Examples of **correct** code for this rule with the default `"never"` option:
42
43```js
44/*eslint template-tag-spacing: "error"*/
45
46func`Hello world`;
47```
48
49### always
50
51Examples of **incorrect** code for this rule with the `"always"` option:
52
53```js
54/*eslint template-tag-spacing: ["error", "always"]*/
55
56func`Hello world`;
57```
58
59Examples of **correct** code for this rule with the `"always"` option:
60
61```js
62/*eslint template-tag-spacing: ["error", "always"]*/
63
64func `Hello world`;
65```
66
67## When Not To Use It
68
69If you don't want to be notified about usage of spacing between tag functions and their template literals, then it's safe to disable this rule.
70
71## Further Reading
72
73If you want to learn more about tagged template literals, check out the links below:
74
75* [Template literals (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals)
76* [Examples of using tagged template literals (Exploring ES6)](http://exploringjs.com/es6/ch_template-literals.html#_examples-of-using-tagged-template-literals)