source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-namespace.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @fileoverview Enforce that namespaces are not used in React elements
3 * @author Yacine Hmito
4 */
5
6'use strict';
7
8const elementType = require('jsx-ast-utils/elementType');
9const docsUrl = require('../util/docsUrl');
10const isCreateElement = require('../util/isCreateElement');
11const report = require('../util/report');
12
13// ------------------------------------------------------------------------------
14// Rule Definition
15// ------------------------------------------------------------------------------
16
17const messages = {
18 noNamespace: 'React component {{name}} must not be in a namespace, as React does not support them',
19};
20
21/** @type {import('eslint').Rule.RuleModule} */
22module.exports = {
23 meta: {
24 docs: {
25 description: 'Enforce that namespaces are not used in React elements',
26 category: 'Possible Errors',
27 recommended: false,
28 url: docsUrl('no-namespace'),
29 },
30
31 messages,
32
33 schema: [],
34 },
35
36 create(context) {
37 return {
38 CallExpression(node) {
39 if (isCreateElement(context, node) && node.arguments.length > 0 && node.arguments[0].type === 'Literal') {
40 const name = node.arguments[0].value;
41 if (typeof name !== 'string' || name.indexOf(':') === -1) return undefined;
42 report(context, messages.noNamespace, 'noNamespace', {
43 node,
44 data: {
45 name,
46 },
47 });
48 }
49 },
50 JSXOpeningElement(node) {
51 const name = elementType(node);
52 if (typeof name !== 'string' || name.indexOf(':') === -1) return undefined;
53 report(context, messages.noNamespace, 'noNamespace', {
54 node,
55 data: {
56 name,
57 },
58 });
59 },
60 };
61 },
62};
Note: See TracBrowser for help on using the repository browser.