mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 17:35:16 +00:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
|
/**
|
|||
|
* @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'
|
|||
|
});
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
};
|