1 | /**
|
---|
2 | * @fileoverview Prevent React to be marked as unused
|
---|
3 | * @author Glen Mailer
|
---|
4 | */
|
---|
5 |
|
---|
6 | 'use strict';
|
---|
7 |
|
---|
8 | const pragmaUtil = require('../util/pragma');
|
---|
9 | const docsUrl = require('../util/docsUrl');
|
---|
10 | const markVariableAsUsed = require('../util/eslint').markVariableAsUsed;
|
---|
11 |
|
---|
12 | // ------------------------------------------------------------------------------
|
---|
13 | // Rule Definition
|
---|
14 | // ------------------------------------------------------------------------------
|
---|
15 |
|
---|
16 | /** @type {import('eslint').Rule.RuleModule} */
|
---|
17 | module.exports = {
|
---|
18 | // eslint-disable-next-line eslint-plugin/prefer-message-ids -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/292
|
---|
19 | meta: {
|
---|
20 | docs: {
|
---|
21 | description: 'Disallow React to be incorrectly marked as unused',
|
---|
22 | category: 'Best Practices',
|
---|
23 | recommended: true,
|
---|
24 | url: docsUrl('jsx-uses-react'),
|
---|
25 | },
|
---|
26 | schema: [],
|
---|
27 | },
|
---|
28 |
|
---|
29 | create(context) {
|
---|
30 | const pragma = pragmaUtil.getFromContext(context);
|
---|
31 | const fragment = pragmaUtil.getFragmentFromContext(context);
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @param {ASTNode} node
|
---|
35 | * @returns {void}
|
---|
36 | */
|
---|
37 | function handleOpeningElement(node) {
|
---|
38 | markVariableAsUsed(pragma, node, context);
|
---|
39 | }
|
---|
40 | // --------------------------------------------------------------------------
|
---|
41 | // Public
|
---|
42 | // --------------------------------------------------------------------------
|
---|
43 |
|
---|
44 | return {
|
---|
45 | JSXOpeningElement: handleOpeningElement,
|
---|
46 | JSXOpeningFragment: handleOpeningElement,
|
---|
47 | JSXFragment(node) {
|
---|
48 | markVariableAsUsed(fragment, node, context);
|
---|
49 | },
|
---|
50 | };
|
---|
51 | },
|
---|
52 | };
|
---|