• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Warn when using template string syntax in regular strings
3 * @author Jeroen Engels
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = {
12    meta: {
13        type: "problem",
14
15        docs: {
16            description: "disallow template literal placeholder syntax in regular strings",
17            category: "Possible Errors",
18            recommended: false,
19            url: "https://eslint.org/docs/rules/no-template-curly-in-string"
20        },
21
22        schema: [],
23
24        messages: {
25            unexpectedTemplateExpression: "Unexpected template string expression."
26        }
27    },
28
29    create(context) {
30        const regex = /\$\{[^}]+\}/u;
31
32        return {
33            Literal(node) {
34                if (typeof node.value === "string" && regex.test(node.value)) {
35                    context.report({
36                        node,
37                        messageId: "unexpectedTemplateExpression"
38                    });
39                }
40            }
41        };
42
43    }
44};
45