UNPKG

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