f7822e961cc1e7afa3be72f3ed0bd984fd87c9ef
[dotfiles/.git] / 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             category: "Possible Errors",
18             recommended: false,
19             url: "https://eslint.org/docs/rules/no-template-curly-in-string"
20         },
21
22         schema: []
23     },
24
25     create(context) {
26         const regex = /\$\{[^}]+\}/u;
27
28         return {
29             Literal(node) {
30                 if (typeof node.value === "string" && regex.test(node.value)) {
31                     context.report({
32                         node,
33                         message: "Unexpected template string expression."
34                     });
35                 }
36             }
37         };
38
39     }
40 };