Bug 1280898 - Set up eslint for calendar files - enable no-caller rule. r=MakeMyDay
authoreslint <eslint@bugzilla.kewis.ch>
Fri, 08 Jul 2016 14:01:38 +0200
changeset 25981 ae8573bfa22abb25c9c5b654809cc2e99a5aa193
parent 25980 64dbe94fb4c8650beb6aa4cd27553f8929e1dd0b
child 25982 8af7d1e8ec53d7994d79512bbca67aa5716dfc62
push id1771
push userclokep@gmail.com
push dateMon, 14 Nov 2016 17:47:53 +0000
treeherdercomm-beta@399ae9d71595 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMakeMyDay
bugs1280898
Bug 1280898 - Set up eslint for calendar files - enable no-caller rule. r=MakeMyDay MozReview-Commit-ID: 9pSOzbExQSx
calendar/.eslintrc
calendar/base/modules/calItemUtils.jsm
--- a/calendar/.eslintrc
+++ b/calendar/.eslintrc
@@ -336,16 +336,19 @@
     "no-unused-expressions": 2,
 
     // Disallow function or var declarations in nested blocks
     "no-inner-declarations": 2,
 
     // Enforce newline before and after dot
     "dot-location": [2, "property"],
 
+    // Disallow Use of caller/callee
+    "no-caller": 2,
+
     // Will enable these rules later
     "block-spacing": 0,
     "no-lonely-if": 0,
     "space-before-blocks": 0,
     "computed-property-spacing": 0,
 
     // The following rules will not be enabled currently, but are kept here for
     // easier updates in the future.
--- a/calendar/base/modules/calItemUtils.jsm
+++ b/calendar/base/modules/calItemUtils.jsm
@@ -37,20 +37,21 @@ itemDiff.prototype = {
     mModifiedOldItems: null,
     mAddedItems: null,
     mDeletedItems: null,
 
     /**
      * Expect the difference engine to be in the given state.
      *
      * @param aState    The state to be in
+     * @param aMethod   The method name expecting the state
      */
-    _expectState: function _expectState(aState) {
+    _expectState: function _expectState(aState, aMethod) {
         if ((this.state & aState) == 0) {
-            throw new Error("itemDiff method " + arguments.callee.caller.name +
+            throw new Error("itemDiff method " + aMethod +
                             " called while in unexpected state " + this.state);
         }
     },
 
     /**
      * Load the difference engine with one item, see load.
      *
      * @param item      The item to load
@@ -61,17 +62,17 @@ itemDiff.prototype = {
 
     /**
      * Loads an array of items. This step cannot be executed
      * after calling the difference methods.
      *
      * @param items     The array of items to load
      */
     load: function load(items) {
-        this._expectState(this.STATE_INITIAL | this.STATE_LOADING);
+        this._expectState(this.STATE_INITIAL | this.STATE_LOADING, "load");
 
         for (let item of items) {
             this.mInitialItems[item.hashId] = item;
         }
 
         this.state = this.STATE_LOADING;
     },
 
@@ -86,17 +87,17 @@ itemDiff.prototype = {
 
     /**
      * Calculate the difference for the array of items. This method should be
      * called after all load methods and before the complete method.
      *
      * @param items     The array of items to calculate difference with
      */
     difference: function difference(items) {
-        this._expectState(this.STATE_INITIAL | this.STATE_LOADING | this.STATE_DIFFERING);
+        this._expectState(this.STATE_INITIAL | this.STATE_LOADING | this.STATE_DIFFERING, "difference");
 
         this.mModifiedOldItems.startBatch();
         this.mModifiedItems.startBatch();
         this.mAddedItems.startBatch();
 
         for (let item of items) {
             if (item.hashId in this.mInitialItems) {
                 let oldItem = this.mInitialItems[item.hashId];
@@ -115,52 +116,52 @@ itemDiff.prototype = {
         this.state = this.STATE_DIFFERING;
     },
 
     /**
      * Tell the engine that all load and difference calls have been made, this
      * makes sure that all item states are correctly returned.
      */
     complete: function complete() {
-        this._expectState(this.STATE_INITIAL | this.STATE_LOADING | this.STATE_DIFFERING);
+        this._expectState(this.STATE_INITIAL | this.STATE_LOADING | this.STATE_DIFFERING, "complete");
 
         this.mDeletedItems.startBatch();
 
         for (let hashId in this.mInitialItems) {
             let item = this.mInitialItems[hashId];
             this.mDeletedItems.addItem(item);
         }
 
         this.mDeletedItems.endBatch();
         this.mInitialItems = {};
 
         this.state = this.STATE_COMPLETED;
     },
 
     /** @return a HashedArray containing the new version of the modified items */
     get modifiedItems() {
-        this._expectState(this.STATE_COMPLETED);
+        this._expectState(this.STATE_COMPLETED, "get modifiedItems");
         return this.mModifiedItems;
     },
 
     /** @return a HashedArray containing the old version of the modified items */
     get modifiedOldItems() {
-        this._expectState(this.STATE_COMPLETED);
+        this._expectState(this.STATE_COMPLETED, "get modifiedOldItems");
         return this.mModifiedOldItems;
     },
 
     /** @return a HashedArray containing added items */
     get addedItems() {
-        this._expectState(this.STATE_COMPLETED);
+        this._expectState(this.STATE_COMPLETED, "get addedItems");
         return this.mAddedItems;
     },
 
     /** @return a HashedArray containing deleted items */
     get deletedItems() {
-        this._expectState(this.STATE_COMPLETED);
+        this._expectState(this.STATE_COMPLETED, "get deletedItems");
         return this.mDeletedItems;
     },
 
     /** @return the number of loaded items */
     get count() {
         return Object.keys(this.mInitialItems).length;
     },