]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-template-curly-in-string.js
import 8.3.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 module.exports = {
12 meta: {
13 type: "problem",
14
15 docs: {
16 description: "disallow template literal placeholder syntax in regular strings",
17 recommended: false,
18 url: "https://eslint.org/docs/rules/no-template-curly-in-string"
19 },
20
21 schema: [],
22
23 messages: {
24 unexpectedTemplateExpression: "Unexpected template string expression."
25 }
26 },
27
28 create(context) {
29 const regex = /\$\{[^}]+\}/u;
30
31 return {
32 Literal(node) {
33 if (typeof node.value === "string" && regex.test(node.value)) {
34 context.report({
35 node,
36 messageId: "unexpectedTemplateExpression"
37 });
38 }
39 }
40 };
41
42 }
43 };