dae3d94f3258945f9b33b743f1c92fb20f00ebdb
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Prevent usage of setState in componentDidMount
3  * @author Yannick Croissant
4  */
5 'use strict';
6
7 // ------------------------------------------------------------------------------
8 // Rule Definition
9 // ------------------------------------------------------------------------------
10
11 module.exports = function(context) {
12
13   // --------------------------------------------------------------------------
14   // Public
15   // --------------------------------------------------------------------------
16
17   return {
18
19     CallExpression: function(node) {
20       var callee = node.callee;
21       if (callee.type !== 'MemberExpression') {
22         return;
23       }
24       if (callee.object.type !== 'ThisExpression' || callee.property.name !== 'setState') {
25         return;
26       }
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') {
30           continue;
31         }
32         context.report(callee, 'Do not use setState in componentDidMount');
33       }
34     }
35   };
36
37 };