UNPKG

958 BJavaScriptView Raw
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 docs: {
14 description: "disallow template literal placeholder syntax in regular strings",
15 category: "Possible Errors",
16 recommended: false
17 },
18
19 schema: []
20 },
21
22 create(context) {
23 const regex = /\$\{[^}]+\}/;
24
25 return {
26 Literal(node) {
27 if (typeof node.value === "string" && regex.test(node.value)) {
28 context.report({
29 node,
30 message: "Unexpected template string expression."
31 });
32 }
33 }
34 };
35
36 }
37};