Sha256: c331b14ffa7b3bc6449a813987f3d927a608cb65414f07c9ff2f2610e71f122b
Contents?: true
Size: 2 KB
Versions: 43
Compression:
Stored size: 2 KB
Contents
/** * @fileoverview Prevent usage of the return value of React.render * @author Dustan Kasten */ 'use strict'; const versionUtil = require('../util/version'); const docsUrl = require('../util/docsUrl'); // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ module.exports = { meta: { docs: { description: 'Prevent usage of the return value of React.render', category: 'Best Practices', recommended: true, url: docsUrl('no-render-return-value') }, schema: [] }, create: function(context) { // -------------------------------------------------------------------------- // Public // -------------------------------------------------------------------------- return { CallExpression: function(node) { const callee = node.callee; const parent = node.parent; if (callee.type !== 'MemberExpression') { return; } let calleeObjectName = /^ReactDOM$/; if (versionUtil.testReactVersion(context, '15.0.0')) { calleeObjectName = /^ReactDOM$/; } else if (versionUtil.testReactVersion(context, '0.14.0')) { calleeObjectName = /^React(DOM)?$/; } else if (versionUtil.testReactVersion(context, '0.13.0')) { calleeObjectName = /^React$/; } if ( callee.object.type !== 'Identifier' || !calleeObjectName.test(callee.object.name) || callee.property.name !== 'render' ) { return; } if ( parent.type === 'VariableDeclarator' || parent.type === 'Property' || parent.type === 'ReturnStatement' || parent.type === 'ArrowFunctionExpression' ) { context.report({ node: callee, message: `Do not depend on the return value from ${callee.object.name}.render` }); } } }; } };
Version data entries
43 entries across 43 versions & 1 rubygems