react-in-jsx-scope.js
961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @fileoverview Prevent missing React when using JSX
* @author Glen Mailer
*/
'use strict';
var variableUtil = require('../util/variable');
var pragmaUtil = require('../util/pragma');
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
module.exports = function(context) {
var pragma = pragmaUtil.getFromContext(context);
var NOT_DEFINED_MESSAGE = '\'{{name}}\' must be in scope when using JSX';
return {
JSXOpeningElement: function(node) {
var variables = variableUtil.variablesInScope(context);
if (variableUtil.findVariable(variables, pragma)) {
return;
}
context.report(node, NOT_DEFINED_MESSAGE, {
name: pragma
});
},
BlockComment: function(node) {
pragma = pragmaUtil.getFromNode(node) || pragma;
}
};
};
module.exports.schema = [];