source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-is-mounted.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @fileoverview Prevent usage of isMounted
3 * @author Joe Lencioni
4 */
5
6'use strict';
7
8const docsUrl = require('../util/docsUrl');
9const getAncestors = require('../util/eslint').getAncestors;
10const report = require('../util/report');
11
12// ------------------------------------------------------------------------------
13// Rule Definition
14// ------------------------------------------------------------------------------
15
16const messages = {
17 noIsMounted: 'Do not use isMounted',
18};
19
20/** @type {import('eslint').Rule.RuleModule} */
21module.exports = {
22 meta: {
23 docs: {
24 description: 'Disallow usage of isMounted',
25 category: 'Best Practices',
26 recommended: true,
27 url: docsUrl('no-is-mounted'),
28 },
29
30 messages,
31
32 schema: [],
33 },
34
35 create(context) {
36 return {
37 CallExpression(node) {
38 const callee = node.callee;
39 if (callee.type !== 'MemberExpression') {
40 return;
41 }
42 if (
43 callee.object.type !== 'ThisExpression'
44 || !('name' in callee.property)
45 || callee.property.name !== 'isMounted'
46 ) {
47 return;
48 }
49 const ancestors = getAncestors(context, node);
50 for (let i = 0, j = ancestors.length; i < j; i++) {
51 if (ancestors[i].type === 'Property' || ancestors[i].type === 'MethodDefinition') {
52 report(context, messages.noIsMounted, 'noIsMounted', {
53 node: callee,
54 });
55 break;
56 }
57 }
58 },
59 };
60 },
61};
Note: See TracBrowser for help on using the repository browser.