UNPKG

1.59 kBJavaScriptView Raw
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
12const astUtils = require("../ast-utils");
13
14//------------------------------------------------------------------------------
15// Rule Definition
16//------------------------------------------------------------------------------
17
18module.exports = {
19 meta: {
20 docs: {
21 description: "disallow multiline strings",
22 category: "Best Practices",
23 recommended: false
24 },
25
26 schema: []
27 },
28
29 create(context) {
30
31 /**
32 * Determines if a given node is part of JSX syntax.
33 * @param {ASTNode} node The node to check.
34 * @returns {boolean} True if the node is a JSX node, false if not.
35 * @private
36 */
37 function isJSXElement(node) {
38 return node.type.indexOf("JSX") === 0;
39 }
40
41 //--------------------------------------------------------------------------
42 // Public API
43 //--------------------------------------------------------------------------
44
45 return {
46
47 Literal(node) {
48 if (astUtils.LINEBREAK_MATCHER.test(node.raw) && !isJSXElement(node.parent)) {
49 context.report({ node, message: "Multiline support is limited to browsers supporting ES5 only." });
50 }
51 }
52 };
53
54 }
55};