no-find-dom-node.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @fileoverview Prevent usage of findDOMNode
* @author Yannick Croissant
*/
'use strict';
const docsUrl = require('../util/docsUrl');
const report = require('../util/report');
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
const messages = {
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',
};
module.exports = {
meta: {
docs: {
description: 'Disallow usage of findDOMNode',
category: 'Best Practices',
recommended: true,
url: docsUrl('no-find-dom-node'),
},
messages,
schema: [],
},
create(context) {
return {
CallExpression(node) {
const callee = node.callee;
const isfindDOMNode = (callee.name === 'findDOMNode')
|| (callee.property && callee.property.name === 'findDOMNode');
if (!isfindDOMNode) {
return;
}
report(context, messages.noFindDOMNode, 'noFindDOMNode', {
node: callee,
});
},
};
},
};