no-malformed-template-literals.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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. schema: [],
  18. messages: {
  19. forbidden:
  20. "ES2018 template literals with invalid escape sequences are forbidden.",
  21. },
  22. },
  23. create(context) {
  24. const reported = new Set()
  25. return {
  26. "TemplateElement[value.cooked=null]"(elementNode) {
  27. const node = elementNode.parent
  28. if (!reported.has(node)) {
  29. reported.add(node)
  30. context.report({ node, messageId: "forbidden" })
  31. }
  32. },
  33. }
  34. },
  35. }