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