]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-multi-str.js
import 8.3.0 source
[pve-eslint.git] / eslint / lib / rules / no-multi-str.js
1 /**
2 * @fileoverview Rule to flag when using multiline strings
3 * @author Ilya Volodin
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const astUtils = require("./utils/ast-utils");
13
14 //------------------------------------------------------------------------------
15 // Rule Definition
16 //------------------------------------------------------------------------------
17
18 module.exports = {
19 meta: {
20 type: "suggestion",
21
22 docs: {
23 description: "disallow multiline strings",
24 recommended: false,
25 url: "https://eslint.org/docs/rules/no-multi-str"
26 },
27
28 schema: [],
29
30 messages: {
31 multilineString: "Multiline support is limited to browsers supporting ES5 only."
32 }
33 },
34
35 create(context) {
36
37 /**
38 * Determines if a given node is part of JSX syntax.
39 * @param {ASTNode} node The node to check.
40 * @returns {boolean} True if the node is a JSX node, false if not.
41 * @private
42 */
43 function isJSXElement(node) {
44 return node.type.indexOf("JSX") === 0;
45 }
46
47 //--------------------------------------------------------------------------
48 // Public API
49 //--------------------------------------------------------------------------
50
51 return {
52
53 Literal(node) {
54 if (astUtils.LINEBREAK_MATCHER.test(node.raw) && !isJSXElement(node.parent)) {
55 context.report({
56 node,
57 messageId: "multilineString"
58 });
59 }
60 }
61 };
62
63 }
64 };