2 * @fileoverview Prevent usage of setState in componentDidMount
3 * @author Yannick Croissant
7 // ------------------------------------------------------------------------------
9 // ------------------------------------------------------------------------------
11 module.exports = function(context) {
13 // --------------------------------------------------------------------------
15 // --------------------------------------------------------------------------
19 CallExpression: function(node) {
20 var callee = node.callee;
21 if (callee.type !== 'MemberExpression') {
24 if (callee.object.type !== 'ThisExpression' || callee.property.name !== 'setState') {
27 var ancestors = context.getAncestors(callee);
28 for (var i = 0, j = ancestors.length; i < j; i++) {
29 if (ancestors[i].type !== 'Property' || ancestors[i].key.name !== 'componentDidMount') {
32 context.report(callee, 'Do not use setState in componentDidMount');