]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-template-curly-in-string.js
import 8.4.0 source
[pve-eslint.git] / eslint / lib / rules / no-template-curly-in-string.js
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
11 /** @type {import('../shared/types').Rule} */
12 module.exports = {
13 meta: {
14 type: "problem",
15
16 docs: {
17 description: "disallow template literal placeholder syntax in regular strings",
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 };