template-tag-spacing
要求或不允许模板标签与其字面之间的间距
此规则报告的一些问题可通过 --fix
命令行选项自动修复
此规则在 ESLint v8.53.0 中已弃用。请在 @stylistic/eslint-plugin-js
中使用 相应的规则。
¥This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js
.
使用 ES6,可以创建名为 标记的模板字面 的函数,其中函数参数由模板字面的字符串和表达式组成。
¥With ES6, it’s possible to create functions called tagged template literals where the function parameters consist of a template literal’s strings and expressions.
使用标记模板字面时,可以在标记函数和模板字面之间插入空格。由于此空格是可选的,因此以下行是等效的:
¥When 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:
let hello = func`Hello world`;
let hello = func `Hello world`;
规则详情
¥Rule Details
此规则旨在保持模板标记函数与其模板字面之间的间距的一致性。
¥This rule aims to maintain consistency around the spacing between template tag functions and their template literals.
选项
¥Options
{
"template-tag-spacing": ["error", "never"]
}
此规则有一个选项,其值可以设置为 "never"
或 "always"
¥This rule has one option whose value can be set to "never"
or "always"
-
"never"
(默认) - 标签函数与其模板字面量之间不允许有空格。¥
"never"
(default) - Disallows spaces between a tag function and its template literal. -
"always"
- 标签函数与其模板字面之间需要一个或多个空格。¥
"always"
- Requires one or more spaces between a tag function and its template literal.
示例
¥Examples
never
使用默认 "never"
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the default "never"
option:
/*eslint template-tag-spacing: "error"*/
func `Hello world`;
使用默认 "never"
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the default "never"
option:
/*eslint template-tag-spacing: "error"*/
func`Hello world`;
always
使用 "always"
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the "always"
option:
/*eslint template-tag-spacing: ["error", "always"]*/
func`Hello world`;
使用 "always"
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the "always"
option:
/*eslint template-tag-spacing: ["error", "always"]*/
func `Hello world`;
何时不使用
¥When Not To Use It
如果你不想收到有关标签函数及其模板字面之间的间距使用情况的通知,那么禁用此规则是安全的。
¥If 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.
版本
此规则是在 ESLint v3.15.0 中引入。