Require or disallow spacing around embedded expressions of template strings
Some problems reported by this rule are automatically fixable by the --fix
command line option
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.
let hello = `hello, ${people.name}!`;
This rule aims to maintain consistency around the spacing inside of template literals.
{
"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 of incorrect code for this rule with the default "never"
option:
/*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:
/*eslint template-curly-spacing: "error"*/
`hello, ${people.name}!`;
`hello, ${
people.name
}!`;
Examples of incorrect code for this rule with the "always"
option:
/*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:
/*eslint template-curly-spacing: ["error", "always"]*/
`hello, ${ people.name }!`;
`hello, ${
people.name
}!`;
If you don’t want to be notified about usage of spacing inside of template strings, then it’s safe to disable this rule.
This rule was introduced in ESLint v2.0.0-rc.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/template-curly-spacing