UNPKG

1.65 kBJavaScriptView Raw
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');
9
10// ------------------------------------------------------------------------------
11// Rule Definition
12// ------------------------------------------------------------------------------
13
14function checkText(node, context) {
15 // since babel-eslint has the wrong node.raw, we'll get the source text
16 const rawValue = context.getSourceCode().getText(node);
17 if (/^\s*\/(\/|\*)/m.test(rawValue)) {
18 // inside component, e.g. <div>literal</div>
19 if (
20 node.parent.type !== 'JSXAttribute'
21 && node.parent.type !== 'JSXExpressionContainer'
22 && node.parent.type.indexOf('JSX') !== -1
23 ) {
24 context.report({
25 node,
26 message: 'Comments inside children section of tag should be placed inside braces'
27 });
28 }
29 }
30}
31
32module.exports = {
33 meta: {
34 docs: {
35 description: 'Comments inside children section of tag should be placed inside braces',
36 category: 'Possible Errors',
37 recommended: true,
38 url: docsUrl('jsx-no-comment-textnodes')
39 },
40
41 schema: [{
42 type: 'object',
43 properties: {},
44 additionalProperties: false
45 }]
46 },
47
48 create(context) {
49 // --------------------------------------------------------------------------
50 // Public
51 // --------------------------------------------------------------------------
52
53 return {
54 Literal(node) {
55 checkText(node, context);
56 },
57 JSXText(node) {
58 checkText(node, context);
59 }
60 };
61 }
62};