no-multi-str.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @fileoverview Rule to flag when using multiline strings
  3. * @author Ilya Volodin
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const astUtils = require("../ast-utils");
  10. //------------------------------------------------------------------------------
  11. // Rule Definition
  12. //------------------------------------------------------------------------------
  13. module.exports = {
  14. meta: {
  15. docs: {
  16. description: "disallow multiline strings",
  17. category: "Best Practices",
  18. recommended: false,
  19. url: "https://eslint.org/docs/rules/no-multi-str"
  20. },
  21. schema: []
  22. },
  23. create(context) {
  24. /**
  25. * Determines if a given node is part of JSX syntax.
  26. * @param {ASTNode} node The node to check.
  27. * @returns {boolean} True if the node is a JSX node, false if not.
  28. * @private
  29. */
  30. function isJSXElement(node) {
  31. return node.type.indexOf("JSX") === 0;
  32. }
  33. //--------------------------------------------------------------------------
  34. // Public API
  35. //--------------------------------------------------------------------------
  36. return {
  37. Literal(node) {
  38. if (astUtils.LINEBREAK_MATCHER.test(node.raw) && !isJSXElement(node.parent)) {
  39. context.report({ node, message: "Multiline support is limited to browsers supporting ES5 only." });
  40. }
  41. }
  42. };
  43. }
  44. };