template-tag-spacing

The --fix option on the command line can automatically fix some of the problems reported by this rule.

Requires or disallow spacing between template tags and their literals.

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"]
}

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

Examples

never

Examples of incorrect code for this rule with the default "never" option:

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

func `Hello world`;

Examples of correct code for this rule with the default "never" option:

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

func`Hello world`;

always

Examples of incorrect code for this rule with the "always" option:

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

func`Hello world`;

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.

Further Reading

Version

This rule was introduced in ESLint 3.15.0.

Resources