Skip to content

Latest commit

 

History

History
85 lines (51 loc) · 1.93 KB

template-tag-spacing.md

File metadata and controls

85 lines (51 loc) · 1.93 KB
规则名 规则类型 深入了解
template-tag-spacing
layout

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`;

规则详解

This rule aims to maintain consistency around the spacing between template tag functions and their template literals.

配置项

{
    "template-tag-spacing": ["error", "never"]
}

This rule has one option whose value can be set to "never" or "always"

  • "never" (default) - Disallows spaces between a tag function and its template literal.
  • "always" - Requires one or more spaces between a tag function and its template literal.

Examples

never

选项 "never" 默认值的 错误 代码示例:

/*eslint template-tag-spacing: "error"*/

func `Hello world`;

选项 "never" 默认值的 正确 代码示例:

::: correct

/*eslint template-tag-spacing: "error"*/

func`Hello world`;

always

选项 "always"错误 代码示例:

/*eslint template-tag-spacing: ["error", "always"]*/

func`Hello world`;

选项 "always"正确 代码示例:

::: correct

/*eslint template-tag-spacing: ["error", "always"]*/

func `Hello world`;

禁用建议

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.