source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/jsx-no-comment-textnodes.js

main
Last change on this file 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
RevLine 
[d565449]1/**
2 * @fileoverview Comments inside children section of tag should be placed inside braces.
3 * @author Ben Vinegar
4 */
5
6'use strict';
7
8const docsUrl = require('../util/docsUrl');
9const getText = require('../util/eslint').getText;
10const report = require('../util/report');
11
12// ------------------------------------------------------------------------------
13// Rule Definition
14// ------------------------------------------------------------------------------
15
16const messages = {
17 putCommentInBraces: 'Comments inside children section of tag should be placed inside braces',
18};
19
20/**
21 * @param {Context} context
22 * @param {ASTNode} node
23 * @returns {void}
24 */
25function checkText(context, node) {
26 // since babel-eslint has the wrong node.raw, we'll get the source text
27 const rawValue = getText(context, node);
28 if (/^\s*\/(\/|\*)/m.test(rawValue)) {
29 // inside component, e.g. <div>literal</div>
30 if (
31 node.parent.type !== 'JSXAttribute'
32 && node.parent.type !== 'JSXExpressionContainer'
33 && node.parent.type.indexOf('JSX') !== -1
34 ) {
35 report(context, messages.putCommentInBraces, 'putCommentInBraces', {
36 node,
37 });
38 }
39 }
40}
41
42/** @type {import('eslint').Rule.RuleModule} */
43module.exports = {
44 meta: {
45 docs: {
46 description: 'Disallow comments from being inserted as text nodes',
47 category: 'Possible Errors',
48 recommended: true,
49 url: docsUrl('jsx-no-comment-textnodes'),
50 },
51
52 messages,
53
54 schema: [],
55 },
56
57 create(context) {
58 // --------------------------------------------------------------------------
59 // Public
60 // --------------------------------------------------------------------------
61
62 return {
63 Literal(node) {
64 checkText(context, node);
65 },
66 JSXText(node) {
67 checkText(context, node);
68 },
69 };
70 },
71};
Note: See TracBrowser for help on using the repository browser.