no-malformed-template-literals.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @author Toru Nagashima <https://github.com/mysticatea>
  3. * See LICENSE file in root directory for full license.
  4. */
  5. "use strict"
  6. module.exports = {
  7. meta: {
  8. docs: {
  9. description:
  10. "disallow template literals with invalid escape sequences.",
  11. category: "ES2018",
  12. recommended: false,
  13. url:
  14. "http://mysticatea.github.io/eslint-plugin-es/rules/no-malformed-template-literals.html",
  15. },
  16. fixable: null,
  17. messages: {
  18. forbidden:
  19. "ES2018 template literals with invalid escape sequences are forbidden.",
  20. },
  21. schema: [],
  22. type: "problem",
  23. },
  24. create(context) {
  25. const reported = new Set()
  26. return {
  27. "TemplateElement[value.cooked=null]"(elementNode) {
  28. const node = elementNode.parent
  29. if (!reported.has(node)) {
  30. reported.add(node)
  31. context.report({ node, messageId: "forbidden" })
  32. }
  33. },
  34. }
  35. },
  36. }