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