source: imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-find-dom-node.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.4 KB
Line 
1/**
2 * @fileoverview Prevent usage of findDOMNode
3 * @author Yannick Croissant
4 */
5
6'use strict';
7
8const docsUrl = require('../util/docsUrl');
9const report = require('../util/report');
10
11// ------------------------------------------------------------------------------
12// Rule Definition
13// ------------------------------------------------------------------------------
14
15const 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} */
20module.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.