|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
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 |
|
|---|
| 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 | /** @type {import('eslint').Rule.RuleModule} */
|
|---|
| 21 | module.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.