source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/jsx-uses-vars.js@ d565449

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.6 KB
Line 
1/**
2 * @fileoverview Prevent variables used in JSX to be marked as unused
3 * @author Yannick Croissant
4 */
5
6'use strict';
7
8const docsUrl = require('../util/docsUrl');
9const markVariableAsUsed = require('../util/eslint').markVariableAsUsed;
10
11// ------------------------------------------------------------------------------
12// Rule Definition
13// ------------------------------------------------------------------------------
14
15const isTagNameRe = /^[a-z]/;
16const isTagName = (name) => isTagNameRe.test(name);
17
18/** @type {import('eslint').Rule.RuleModule} */
19module.exports = {
20 // eslint-disable-next-line eslint-plugin/prefer-message-ids -- https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/292
21 meta: {
22 docs: {
23 description: 'Disallow variables used in JSX to be incorrectly marked as unused',
24 category: 'Best Practices',
25 recommended: true,
26 url: docsUrl('jsx-uses-vars'),
27 },
28 schema: [],
29 },
30
31 create(context) {
32 return {
33 JSXOpeningElement(node) {
34 let name;
35 if (node.name.namespace) {
36 // <Foo:Bar>
37 return;
38 }
39 if (node.name.name) {
40 // <Foo>
41 name = node.name.name;
42 // Exclude lowercase tag names like <div>
43 if (isTagName(name)) {
44 return;
45 }
46 } else if (node.name.object) {
47 // <Foo...Bar>
48 let parent = node.name.object;
49 while (parent.object) {
50 parent = parent.object;
51 }
52 name = parent.name;
53 } else {
54 return;
55 }
56
57 markVariableAsUsed(name, node, context);
58 },
59
60 };
61 },
62};
Note: See TracBrowser for help on using the repository browser.