no-template-curly-in-string.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @fileoverview Warn when using template string syntax in regular strings
  3. * @author Jeroen Engels
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. docs: {
  12. description: "disallow template literal placeholder syntax in regular strings",
  13. category: "Possible Errors",
  14. recommended: false,
  15. url: "https://eslint.org/docs/rules/no-template-curly-in-string"
  16. },
  17. schema: []
  18. },
  19. create(context) {
  20. const regex = /\$\{[^}]+\}/;
  21. return {
  22. Literal(node) {
  23. if (typeof node.value === "string" && regex.test(node.value)) {
  24. context.report({
  25. node,
  26. message: "Unexpected template string expression."
  27. });
  28. }
  29. }
  30. };
  31. }
  32. };