main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview Prevent missing React when using JSX
|
---|
| 3 | * @author Glen Mailer
|
---|
| 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 | const report = require('../util/report');
|
---|
| 12 |
|
---|
| 13 | // -----------------------------------------------------------------------------
|
---|
| 14 | // Rule Definition
|
---|
| 15 | // -----------------------------------------------------------------------------
|
---|
| 16 |
|
---|
| 17 | const messages = {
|
---|
| 18 | notInScope: '\'{{name}}\' must be in scope when using JSX',
|
---|
| 19 | };
|
---|
| 20 |
|
---|
| 21 | /** @type {import('eslint').Rule.RuleModule} */
|
---|
| 22 | module.exports = {
|
---|
| 23 | meta: {
|
---|
| 24 | docs: {
|
---|
| 25 | description: 'Disallow missing React when using JSX',
|
---|
| 26 | category: 'Possible Errors',
|
---|
| 27 | recommended: true,
|
---|
| 28 | url: docsUrl('react-in-jsx-scope'),
|
---|
| 29 | },
|
---|
| 30 |
|
---|
| 31 | messages,
|
---|
| 32 |
|
---|
| 33 | schema: [],
|
---|
| 34 | },
|
---|
| 35 |
|
---|
| 36 | create(context) {
|
---|
| 37 | const pragma = pragmaUtil.getFromContext(context);
|
---|
| 38 |
|
---|
| 39 | function checkIfReactIsInScope(node) {
|
---|
| 40 | if (variableUtil.getVariableFromContext(context, node, pragma)) {
|
---|
| 41 | return;
|
---|
| 42 | }
|
---|
| 43 | report(context, messages.notInScope, 'notInScope', {
|
---|
| 44 | node,
|
---|
| 45 | data: {
|
---|
| 46 | name: pragma,
|
---|
| 47 | },
|
---|
| 48 | });
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | return {
|
---|
| 52 | JSXOpeningElement: checkIfReactIsInScope,
|
---|
| 53 | JSXOpeningFragment: checkIfReactIsInScope,
|
---|
| 54 | };
|
---|
| 55 | },
|
---|
| 56 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.