Bug 1329012 - Enable the no-useless-call rule for eslint and fix the nine errors that it caught. r?mossop draft
authorJared Wein <jwein@mozilla.com>
Thu, 05 Jan 2017 12:56:53 -0500
changeset 456530 cae79f4257cdef24a40ba7298087630a997c476e
parent 456529 5e11894b2e4040c6f482c30979b9787ddafca598
child 456531 36d9ccc9fa08b31c4ae15695c86a94323aac818c
push id40533
push userbmo:jaws@mozilla.com
push dateThu, 05 Jan 2017 22:09:44 +0000
reviewersmossop
bugs1329012
milestone53.0a1
Bug 1329012 - Enable the no-useless-call rule for eslint and fix the nine errors that it caught. r?mossop MozReview-Commit-ID: 57vvfJlyvfW
browser/base/content/browser-plugins.js
toolkit/.eslintrc.js
toolkit/components/ctypes/tests/unit/test_jsctypes.js
toolkit/modules/Integration.jsm
toolkit/modules/Promise-backend.js
toolkit/modules/Task.jsm
toolkit/mozapps/extensions/test/browser/head.js
--- a/browser/base/content/browser-plugins.js
+++ b/browser/base/content/browser-plugins.js
@@ -67,17 +67,17 @@ var gPluginHandler = {
           this.submitReport(msg.data.runID, msg.data.keyVals, msg.data.submitURLOptIn);
         }
         break;
       case "PluginContent:LinkClickCallback":
         switch (msg.data.name) {
           case "managePlugins":
           case "openHelpPage":
           case "openPluginUpdatePage":
-            this[msg.data.name].call(this, msg.data.pluginTag);
+            this[msg.data.name](msg.data.pluginTag);
             break;
         }
         break;
       default:
         Cu.reportError("gPluginHandler did not expect to handle message " + msg.name);
         break;
     }
   },
--- a/toolkit/.eslintrc.js
+++ b/toolkit/.eslintrc.js
@@ -188,16 +188,19 @@ module.exports = {
       "vars": "local",
       "varsIgnorePattern": "^Cc|Ci|Cu|Cr|EXPORTED_SYMBOLS",
       "args": "none",
     }],
 
     // No using variables before defined
     // "no-use-before-define": ["error", "nofunc"],
 
+    // Disallow unnecessary .call() and .apply()
+    "no-useless-call": "error",
+
     // No using with
     "no-with": "error",
 
     // Require object-literal shorthand with ES6 method syntax
     "object-shorthand": ["error", "always", { "avoidQuotes": true }],
 
     // Disallow async functions which have no await expression
     "require-await": "error",
--- a/toolkit/components/ctypes/tests/unit/test_jsctypes.js
+++ b/toolkit/components/ctypes/tests/unit/test_jsctypes.js
@@ -2488,24 +2488,26 @@ function run_function_tests(library) {
   // for test_ansi_len itself.
   let ptr = test_fnptr();
   do_check_eq(ptrValue(test_ansi_len), ptrValue(ptr));
 
   // Test that we can call ptr().
   do_check_eq(ptr("function pointers rule!"), 23);
 
   // Test that we can call via call and apply
+  /* eslint-disable no-useless-call */
   do_check_eq(ptr.call(null, "function pointers rule!"), 23);
   do_check_eq(ptr.apply(null, ["function pointers rule!"]), 23);
 
   // Test that we cannot call non-function pointers via call and apply
   let p_t = ctypes.PointerType(ctypes.int32_t);
   let p = p_t();
   do_check_throws(function() { p.call(null, "woo"); }, TypeError);
   do_check_throws(function() { p.apply(null, ["woo"]); }, TypeError);
+  /* eslint-enable no-useless-call */
 
   // Test the function pointers still behave as regular pointers
   do_check_false(ptr.isNull(), "PointerType methods should still be valid");
 
   // Test that library.declare() returns data of type FunctionType.ptr, and that
   // it is immutable.
   do_check_true(test_ansi_len.constructor.targetType.__proto__ ===
     ctypes.FunctionType.prototype);
--- a/toolkit/modules/Integration.jsm
+++ b/toolkit/modules/Integration.jsm
@@ -228,17 +228,17 @@ this.IntegrationPoint.prototype = {
     // combined object using the "this" reference in integration methods.
     let overrideFnArray = [...this._overrideFns, () => this._combined];
 
     let combined = root;
     for (let overrideFn of overrideFnArray) {
       try {
         // Obtain a new set of methods from the next override function in the
         // list, specifying the current combined object as the base argument.
-        let override = overrideFn.call(null, combined);
+        let override = overrideFn(combined);
 
         // Retrieve a list of property descriptors from the returned object, and
         // use them to build a new combined object whose prototype points to the
         // previous combined object.
         let descriptors = {};
         for (let name of Object.getOwnPropertyNames(override)) {
           descriptors[name] = Object.getOwnPropertyDescriptor(override, name);
         }
--- a/toolkit/modules/Promise-backend.js
+++ b/toolkit/modules/Promise-backend.js
@@ -377,17 +377,17 @@ this.Promise = function Promise(aExecuto
   Object.seal(this);
 
   let resolve = PromiseWalker.completePromise
                              .bind(PromiseWalker, this, STATUS_RESOLVED);
   let reject = PromiseWalker.completePromise
                             .bind(PromiseWalker, this, STATUS_REJECTED);
 
   try {
-    aExecutor.call(undefined, resolve, reject);
+    aExecutor(resolve, reject);
   } catch (ex) {
     reject(ex);
   }
 }
 
 /**
  * Calls one of the provided functions as soon as this promise is either
  * resolved or rejected.  A new promise is returned, whose state evolves
--- a/toolkit/modules/Task.jsm
+++ b/toolkit/modules/Task.jsm
@@ -158,17 +158,17 @@ this.Task = {
    *          returned promise.
    *        - If you specify anything else, you get a promise that is already
    *          resolved with the specified value.
    *
    * @return A promise object where you can register completion callbacks to be
    *         called when the task terminates.
    */
   spawn: function Task_spawn(aTask) {
-    return createAsyncFunction(aTask).call(undefined);
+    return createAsyncFunction(aTask)();
   },
 
   /**
    * Create and return an 'async function' that starts a new task.
    *
    * This is similar to 'spawn' except that it doesn't immediately start
    * the task, it binds the task to the async function's 'this' object and
    * arguments, and it requires the task to be a function.
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -1413,17 +1413,17 @@ MockInstall.prototype = {
     var result = AddonManagerPrivate.callInstallListeners(aMethod, this.listeners,
                                                           this, this.addon);
 
     // Call test listeners after standard listeners to remove race condition
     // between standard and test listeners
     for (let listener of this.testListeners) {
       try {
         if (aMethod in listener)
-          if (listener[aMethod].call(listener, this, this.addon) === false)
+          if (listener[aMethod](this, this.addon) === false)
             result = false;
       } catch (e) {
         ok(false, "Test listener threw exception: " + e);
       }
     }
 
     return result;
   }