Skip to content

Latest commit

Β 

History

History
48 lines (32 loc) Β· 1.97 KB

no-incorrect-template-string-interpolation.md

File metadata and controls

48 lines (32 loc) Β· 1.97 KB

no-incorrect-template-string-interpolation

πŸ“ Disallow incorrect template literal interpolation syntax.

πŸ’ΌπŸš« This rule is enabled in the βœ… recommended config. This rule is disabled in the β˜‘οΈ unopinionated config.

πŸ’‘ This rule is manually fixable by editor suggestions.

Template literal interpolation uses ${expression}. This rule catches likely mistakes where simple identifier or member-expression interpolation was written as {name} or $name} inside an untagged template literal.

This rule is intentionally narrow. It does not report arbitrary expression text like {name + suffix} or other placeholder syntaxes like {{name}}, and it ignores tagged template literals because tags often use braces for other languages such as HTML, CSS, GraphQL, or i18n templates. It also ignores named import/export specifiers like import {foo} from "bar", destructuring declarations like const {foo} = bar, and braces inside block comments such as @param {string} in embedded JSDoc, which are all common in code-generation templates.

Disable this rule for files that intentionally use simple brace placeholders like /users/{id} or contain other brace syntax such as object literals (`const x = {foo}`) in untagged template literals.

Examples

// ❌
const greeting = `Hello {name}`;

// ❌
const greeting = `Hello $user.name}`;

// βœ…
const greeting = `Hello ${name}`;

// βœ…
const greeting = `Hello ${user.name}`;

// βœ…
const query = gql`query { user { name } }`;

// βœ…
const code = `import {foo} from "bar";`;

// βœ…
const code = `const {foo} = bar;`;

// βœ…
const code = `
	/**
	 * @param {string} id
	 */
`;