|
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.4 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @fileoverview Prevent usage of findDOMNode
|
|---|
| 3 | * @author Yannick Croissant
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | 'use strict';
|
|---|
| 7 |
|
|---|
| 8 | const docsUrl = require('../util/docsUrl');
|
|---|
| 9 | const report = require('../util/report');
|
|---|
| 10 |
|
|---|
| 11 | // ------------------------------------------------------------------------------
|
|---|
| 12 | // Rule Definition
|
|---|
| 13 | // ------------------------------------------------------------------------------
|
|---|
| 14 |
|
|---|
| 15 | const messages = {
|
|---|
| 16 | noFindDOMNode: 'Do not use findDOMNode. It doesn’t work with function components and is deprecated in StrictMode. See https://reactjs.org/docs/react-dom.html#finddomnode',
|
|---|
| 17 | };
|
|---|
| 18 |
|
|---|
| 19 | /** @type {import('eslint').Rule.RuleModule} */
|
|---|
| 20 | module.exports = {
|
|---|
| 21 | meta: {
|
|---|
| 22 | docs: {
|
|---|
| 23 | description: 'Disallow usage of findDOMNode',
|
|---|
| 24 | category: 'Best Practices',
|
|---|
| 25 | recommended: true,
|
|---|
| 26 | url: docsUrl('no-find-dom-node'),
|
|---|
| 27 | },
|
|---|
| 28 |
|
|---|
| 29 | messages,
|
|---|
| 30 |
|
|---|
| 31 | schema: [],
|
|---|
| 32 | },
|
|---|
| 33 |
|
|---|
| 34 | create(context) {
|
|---|
| 35 | return {
|
|---|
| 36 | CallExpression(node) {
|
|---|
| 37 | const callee = node.callee;
|
|---|
| 38 |
|
|---|
| 39 | const isFindDOMNode = ('name' in callee && callee.name === 'findDOMNode') || (
|
|---|
| 40 | 'property' in callee
|
|---|
| 41 | && callee.property
|
|---|
| 42 | && 'name' in callee.property
|
|---|
| 43 | && callee.property.name === 'findDOMNode'
|
|---|
| 44 | );
|
|---|
| 45 |
|
|---|
| 46 | if (!isFindDOMNode) {
|
|---|
| 47 | return;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | report(context, messages.noFindDOMNode, 'noFindDOMNode', {
|
|---|
| 51 | node: callee,
|
|---|
| 52 | });
|
|---|
| 53 | },
|
|---|
| 54 | };
|
|---|
| 55 | },
|
|---|
| 56 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.