2024-08-09 12:04:48 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Warn when using template string syntax in regular strings
|
|
|
|
* @author Jeroen Engels
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2024-08-21 06:34:30 +00:00
|
|
|
/** @type {import('../shared/types').Rule} */
|
2024-08-09 12:04:48 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: "problem",
|
|
|
|
|
|
|
|
docs: {
|
2024-08-21 06:34:30 +00:00
|
|
|
description: "Disallow template literal placeholder syntax in regular strings",
|
2024-08-09 12:04:48 +00:00
|
|
|
recommended: false,
|
2024-08-21 06:34:30 +00:00
|
|
|
url: "https://eslint.org/docs/latest/rules/no-template-curly-in-string"
|
2024-08-09 12:04:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
schema: [],
|
|
|
|
|
|
|
|
messages: {
|
|
|
|
unexpectedTemplateExpression: "Unexpected template string expression."
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
create(context) {
|
|
|
|
const regex = /\$\{[^}]+\}/u;
|
|
|
|
|
|
|
|
return {
|
|
|
|
Literal(node) {
|
|
|
|
if (typeof node.value === "string" && regex.test(node.value)) {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
messageId: "unexpectedTemplateExpression"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|