-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
jsx-uses-react.js
52 lines (45 loc) · 1.54 KB
/
jsx-uses-react.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @fileoverview Prevent React to be marked as unused
* @author Glen Mailer
*/
'use strict';
const pragmaUtil = require('../util/pragma');
const docsUrl = require('../util/docsUrl');
const markVariableAsUsed = require('../util/eslint').markVariableAsUsed;
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
// eslint-disable-next-line eslint-plugin/prefer-message-ids -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/292
meta: {
docs: {
description: 'Disallow React to be incorrectly marked as unused',
category: 'Best Practices',
recommended: true,
url: docsUrl('jsx-uses-react'),
},
schema: [],
},
create(context) {
const pragma = pragmaUtil.getFromContext(context);
const fragment = pragmaUtil.getFragmentFromContext(context);
/**
* @param {ASTNode} node
* @returns {void}
*/
function handleOpeningElement(node) {
markVariableAsUsed(pragma, node, context);
}
// --------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
JSXOpeningElement: handleOpeningElement,
JSXOpeningFragment: handleOpeningElement,
JSXFragment(node) {
markVariableAsUsed(fragment, node, context);
},
};
},
};