1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /**
- * @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 doesn’t 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'
- });
- }
- };
- }
- };
|