main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[d565449] | 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 | /** @type {import('../shared/types').Rule} */
|
---|
| 19 | module.exports = {
|
---|
| 20 | meta: {
|
---|
| 21 | type: "suggestion",
|
---|
| 22 |
|
---|
| 23 | docs: {
|
---|
| 24 | description: "Disallow multiline strings",
|
---|
| 25 | recommended: false,
|
---|
| 26 | url: "https://eslint.org/docs/latest/rules/no-multi-str"
|
---|
| 27 | },
|
---|
| 28 |
|
---|
| 29 | schema: [],
|
---|
| 30 |
|
---|
| 31 | messages: {
|
---|
| 32 | multilineString: "Multiline support is limited to browsers supporting ES5 only."
|
---|
| 33 | }
|
---|
| 34 | },
|
---|
| 35 |
|
---|
| 36 | create(context) {
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Determines if a given node is part of JSX syntax.
|
---|
| 40 | * @param {ASTNode} node The node to check.
|
---|
| 41 | * @returns {boolean} True if the node is a JSX node, false if not.
|
---|
| 42 | * @private
|
---|
| 43 | */
|
---|
| 44 | function isJSXElement(node) {
|
---|
| 45 | return node.type.indexOf("JSX") === 0;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | //--------------------------------------------------------------------------
|
---|
| 49 | // Public API
|
---|
| 50 | //--------------------------------------------------------------------------
|
---|
| 51 |
|
---|
| 52 | return {
|
---|
| 53 |
|
---|
| 54 | Literal(node) {
|
---|
| 55 | if (astUtils.LINEBREAK_MATCHER.test(node.raw) && !isJSXElement(node.parent)) {
|
---|
| 56 | context.report({
|
---|
| 57 | node,
|
---|
| 58 | messageId: "multilineString"
|
---|
| 59 | });
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.