/
drndsv
/
react
Обзор
Документация
Войти
/
drndsv
/
react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/eslint-plugin-react/lib/rules/react-in-jsx-scope.js
56 строк
1 KB
drndsv
Initial commit
14 апр 2025, 22:53
14 апр 2025, 22:53
641ac8a
Код
Авторство
О чём код?
/** * @fileoverview Prevent missing React when using JSX * @author Glen Mailer */ 'use strict'; const variableUtil = require('../util/variable'); const pragmaUtil = require('../util/pragma'); const docsUrl = require('../util/docsUrl'); const report = require('../util/report'); // ----------------------------------------------------------------------------- // Rule Definition // ----------------------------------------------------------------------------- const messages = { notInScope: '\'{{name}}\' must be in scope when using JSX', }; module.exports = { meta: { docs: { description: 'Disallow missing React when using JSX', category: 'Possible Errors', recommended: true, url: docsUrl('react-in-jsx-scope'), }, messages, schema: [], }, create(context) { const pragma = pragmaUtil.getFromContext(context); function checkIfReactIsInScope(node) { const variables = variableUtil.variablesInScope(context); if (variableUtil.findVariable(variables, pragma)) { return; } report(context, messages.notInScope, 'notInScope', { node, data: { name: pragma, }, }); } return { JSXOpeningElement: checkIfReactIsInScope, JSXOpeningFragment: checkIfReactIsInScope, }; }, };