GoScrobble/web/node_modules/eslint-plugin-react/lib/rules/no-find-dom-node.js

54 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2022-04-25 02:47:15 +00:00
/**
* @fileoverview Prevent usage of findDOMNode
* @author Yannick Croissant
*/
'use strict';
const docsUrl = require('../util/docsUrl');
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'Prevent usage of findDOMNode',
category: 'Best Practices',
recommended: true,
url: docsUrl('no-find-dom-node')
},
messages: {
noFindDOMNode: 'Do not use findDOMNode. It doesnt work with function components and is deprecated in StrictMode. See https://reactjs.org/docs/react-dom.html#finddomnode'
},
schema: []
},
create(context) {
// --------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
return {
CallExpression(node) {
const callee = node.callee;
const isfindDOMNode = (callee.name === 'findDOMNode')
|| (callee.property && callee.property.name === 'findDOMNode');
if (!isfindDOMNode) {
return;
}
context.report({
node: callee,
messageId: 'noFindDOMNode'
});
}
};
}
};