diff --git a/lib/rules/react-in-jsx-scope.js b/lib/rules/react-in-jsx-scope.js index 492f9e3c4d..c9a39f92a1 100644 --- a/lib/rules/react-in-jsx-scope.js +++ b/lib/rules/react-in-jsx-scope.js @@ -27,22 +27,23 @@ module.exports = { const pragma = pragmaUtil.getFromContext(context); const NOT_DEFINED_MESSAGE = '\'{{name}}\' must be in scope when using JSX'; - return { - - JSXOpeningElement: function(node) { - const variables = variableUtil.variablesInScope(context); - if (variableUtil.findVariable(variables, pragma)) { - return; - } - context.report({ - node: node, - message: NOT_DEFINED_MESSAGE, - data: { - name: pragma - } - }); + function checkIfReactIsInScope(node) { + const variables = variableUtil.variablesInScope(context); + if (variableUtil.findVariable(variables, pragma)) { + return; } + context.report({ + node: node, + message: NOT_DEFINED_MESSAGE, + data: { + name: pragma + } + }); + } + return { + JSXOpeningElement: checkIfReactIsInScope, + JSXOpeningFragment: checkIfReactIsInScope }; } }; diff --git a/tests/lib/rules/react-in-jsx-scope.js b/tests/lib/rules/react-in-jsx-scope.js index 3d76709fb8..1bd9201c96 100644 --- a/tests/lib/rules/react-in-jsx-scope.js +++ b/tests/lib/rules/react-in-jsx-scope.js @@ -36,6 +36,7 @@ ruleTester.run('react-in-jsx-scope', rule, { valid: [ {code: 'var React, App; ;'}, {code: 'var React; ;'}, + {code: 'var React; <>fragment;', parser: 'babel-eslint'}, {code: 'var React; ;'}, {code: 'var React, App, a=1; ;'}, {code: 'var React, App, a=1; function elem() { return ; }'}, @@ -64,6 +65,10 @@ ruleTester.run('react-in-jsx-scope', rule, { }, { code: 'var a = ;', errors: [{message: '\'React\' must be in scope when using JSX'}] + }, { + code: 'var a = <>fragment;', + parser: 'babel-eslint', + errors: [{message: '\'React\' must be in scope when using JSX'}] }, { code: '/** @jsx React.DOM */ var a = ;', errors: [{message: '\'React\' must be in scope when using JSX'}]