mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-10-05 05:20:49 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
83 lines
1.7 KiB
Markdown
83 lines
1.7 KiB
Markdown
# Enforce Usage of Spacing in Template Strings (template-curly-spacing)
|
|
|
|
We can embed expressions in template strings with using a pair of `${` and `}`.
|
|
|
|
This rule can force usage of spacing _within_ the curly brace pair according to style guides.
|
|
|
|
```js
|
|
let hello = `hello, ${people.name}!`;
|
|
```
|
|
|
|
## Rule Details
|
|
|
|
This rule aims to maintain consistency around the spacing inside of template literals.
|
|
|
|
## Options
|
|
|
|
```json
|
|
{
|
|
"template-curly-spacing": ["error", "never"]
|
|
}
|
|
```
|
|
|
|
This rule has one option which has either `"never"` or `"always"` as value.
|
|
|
|
* `"never"` (by default) - Disallows spaces inside of the curly brace pair.
|
|
* `"always"` - Requires one or more spaces inside of the curly brace pair.
|
|
|
|
## Examples
|
|
|
|
### never
|
|
|
|
Examples of **incorrect** code for this rule with the default `"never"` option:
|
|
|
|
```js
|
|
/*eslint template-curly-spacing: "error"*/
|
|
|
|
`hello, ${ people.name}!`;
|
|
`hello, ${people.name }!`;
|
|
|
|
`hello, ${ people.name }!`;
|
|
```
|
|
|
|
Examples of **correct** code for this rule with the default `"never"` option:
|
|
|
|
```js
|
|
/*eslint template-curly-spacing: "error"*/
|
|
|
|
`hello, ${people.name}!`;
|
|
|
|
`hello, ${
|
|
people.name
|
|
}!`;
|
|
```
|
|
|
|
### always
|
|
|
|
Examples of **incorrect** code for this rule with the `"always"` option:
|
|
|
|
```js
|
|
/*eslint template-curly-spacing: ["error", "always"]*/
|
|
|
|
`hello, ${ people.name}!`;
|
|
`hello, ${people.name }!`;
|
|
|
|
`hello, ${people.name}!`;
|
|
```
|
|
|
|
Examples of **correct** code for this rule with the `"always"` option:
|
|
|
|
```js
|
|
/*eslint template-curly-spacing: ["error", "always"]*/
|
|
|
|
`hello, ${ people.name }!`;
|
|
|
|
`hello, ${
|
|
people.name
|
|
}!`;
|
|
```
|
|
|
|
## When Not To Use It
|
|
|
|
If you don't want to be notified about usage of spacing inside of template strings, then it's safe to disable this rule.
|