source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-this-in-sfc.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.3 KB
RevLine 
[d565449]1/**
2 * @fileoverview Report "this" being used in stateless functional components.
3 */
4
5'use strict';
6
7const Components = require('../util/Components');
8const docsUrl = require('../util/docsUrl');
9const report = require('../util/report');
10
11// ------------------------------------------------------------------------------
12// Rule Definition
13// ------------------------------------------------------------------------------
14
15const messages = {
16 noThisInSFC: 'Stateless functional components should not use `this`',
17};
18
19/** @type {import('eslint').Rule.RuleModule} */
20module.exports = {
21 meta: {
22 docs: {
23 description: 'Disallow `this` from being used in stateless functional components',
24 category: 'Possible Errors',
25 recommended: false,
26 url: docsUrl('no-this-in-sfc'),
27 },
28
29 messages,
30
31 schema: [],
32 },
33
34 create: Components.detect((context, components, utils) => ({
35 MemberExpression(node) {
36 if (node.object.type === 'ThisExpression') {
37 const component = components.get(utils.getParentStatelessComponent(node));
38 if (!component || (component.node && component.node.parent && component.node.parent.type === 'Property')) {
39 return;
40 }
41 report(context, messages.noThisInSFC, 'noThisInSFC', {
42 node,
43 });
44 }
45 },
46 })),
47};
Note: See TracBrowser for help on using the repository browser.