1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const variableUtil = require('../util/variable');
|
9 | const pragmaUtil = require('../util/pragma');
|
10 | const docsUrl = require('../util/docsUrl');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | module.exports = {
|
17 | meta: {
|
18 | docs: {
|
19 | description: 'Prevent missing React when using JSX',
|
20 | category: 'Possible Errors',
|
21 | recommended: true,
|
22 | url: docsUrl('react-in-jsx-scope')
|
23 | },
|
24 | schema: []
|
25 | },
|
26 |
|
27 | create(context) {
|
28 | const pragma = pragmaUtil.getFromContext(context);
|
29 | const NOT_DEFINED_MESSAGE = '\'{{name}}\' must be in scope when using JSX';
|
30 |
|
31 | function checkIfReactIsInScope(node) {
|
32 | const variables = variableUtil.variablesInScope(context);
|
33 | if (variableUtil.findVariable(variables, pragma)) {
|
34 | return;
|
35 | }
|
36 | context.report({
|
37 | node,
|
38 | message: NOT_DEFINED_MESSAGE,
|
39 | data: {
|
40 | name: pragma
|
41 | }
|
42 | });
|
43 | }
|
44 |
|
45 | return {
|
46 | JSXOpeningElement: checkIfReactIsInScope,
|
47 | JSXOpeningFragment: checkIfReactIsInScope
|
48 | };
|
49 | }
|
50 | };
|