1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const docsUrl = require('../util/docsUrl');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function checkText(node, context) {
|
15 |
|
16 | const rawValue = context.getSourceCode().getText(node);
|
17 | if (/^\s*\/(\/|\*)/m.test(rawValue)) {
|
18 |
|
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 |
|
32 | module.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 |
|
51 |
|
52 |
|
53 | return {
|
54 | Literal(node) {
|
55 | checkText(node, context);
|
56 | },
|
57 | JSXText(node) {
|
58 | checkText(node, context);
|
59 | }
|
60 | };
|
61 | }
|
62 | };
|