UNPKG

1.41 kBJavaScriptView Raw
1/**
2 * @fileoverview Prevent usage of isMounted
3 * @author Joe Lencioni
4 */
5
6'use strict';
7
8const docsUrl = require('../util/docsUrl');
9
10// ------------------------------------------------------------------------------
11// Rule Definition
12// ------------------------------------------------------------------------------
13
14module.exports = {
15 meta: {
16 docs: {
17 description: 'Prevent usage of isMounted',
18 category: 'Best Practices',
19 recommended: true,
20 url: docsUrl('no-is-mounted')
21 },
22 schema: []
23 },
24
25 create(context) {
26 // --------------------------------------------------------------------------
27 // Public
28 // --------------------------------------------------------------------------
29
30 return {
31
32 CallExpression(node) {
33 const callee = node.callee;
34 if (callee.type !== 'MemberExpression') {
35 return;
36 }
37 if (callee.object.type !== 'ThisExpression' || callee.property.name !== 'isMounted') {
38 return;
39 }
40 const ancestors = context.getAncestors(callee);
41 for (let i = 0, j = ancestors.length; i < j; i++) {
42 if (ancestors[i].type === 'Property' || ancestors[i].type === 'MethodDefinition') {
43 context.report({
44 node: callee,
45 message: 'Do not use isMounted'
46 });
47 break;
48 }
49 }
50 }
51 };
52 }
53};