Bug 1257246: Update webextension APIs for eslint 2. r=kmag
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 05 Apr 2016 11:30:51 -0700
changeset 349015 bf854efd8e651419fb1135cde27580b74fc251fe
parent 349014 db2d6e47a3f4769eb2eede2ec521a8249c0fc6aa
child 349016 b332ba21d743520bdeaf2ba7ce3020ee89378e4e
push id14989
push userdtownsend@mozilla.com
push dateFri, 08 Apr 2016 20:09:09 +0000
reviewerskmag
bugs1257246
milestone48.0a1
Bug 1257246: Update webextension APIs for eslint 2. r=kmag ESLint 2 now flags anonymous generator functions that don't match the generator-star-spacing rule so this mostly is fixing that. MozReview-Commit-ID: 5sLaF26sd0E
browser/components/extensions/ext-commands.js
browser/components/extensions/test/browser/browser_ext_currentWindow.js
browser/components/extensions/test/browser/browser_ext_getViews.js
browser/components/extensions/test/browser/file_popup_api_injection_a.html
browser/components/extensions/test/browser/file_popup_api_injection_b.html
browser/components/extensions/test/browser/head.js
toolkit/components/extensions/.eslintrc
toolkit/components/extensions/ExtensionContent.jsm
toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_download.html
toolkit/components/extensions/test/mochitest/test_ext_webrequest.html
--- a/browser/components/extensions/ext-commands.js
+++ b/browser/components/extensions/ext-commands.js
@@ -190,21 +190,21 @@ CommandList.prototype = {
    *    ["Ctrl", "Shift"] |   "accel shift"
    *    ["MacCtrl"]       |   "control"
    *
    * @param {Array} chromeModifiers The array of chrome modifiers.
    * @return The constructed value for the Key's 'modifiers' attribute.
    */
   getModifiersAttribute(chromeModifiers) {
     let modifiersMap = {
-      "Alt"     : "alt",
-      "Command" : "accel",
-      "Ctrl"    : "accel",
-      "MacCtrl" : "control",
-      "Shift"   : "shift",
+      "Alt": "alt",
+      "Command": "accel",
+      "Ctrl": "accel",
+      "MacCtrl": "control",
+      "Shift": "shift",
     };
     return Array.from(chromeModifiers, modifier => {
       return modifiersMap[modifier];
     }).join(" ");
   },
 };
 
 
--- a/browser/components/extensions/test/browser/browser_ext_currentWindow.js
+++ b/browser/components/extensions/test/browser/browser_ext_currentWindow.js
@@ -117,21 +117,21 @@ add_task(function* () {
     yield callback();
 
     closeBrowserAction(extension, win);
   }
 
   // Set focus to some other window.
   yield focusWindow(window);
 
-  yield triggerPopup(win1, function*() {
+  yield triggerPopup(win1, function* () {
     yield checkWindow("popup", winId1, "win1");
   });
 
-  yield triggerPopup(win2, function*() {
+  yield triggerPopup(win2, function* () {
     yield checkWindow("popup", winId2, "win2");
   });
 
   function* triggerPage(winId, name) {
     extension.sendMessage("background-open-page", winId);
     yield extension.awaitMessage("page-ready");
     yield checkWindow("page", winId, name);
     extension.sendMessage("background-close-page", winId);
--- a/browser/components/extensions/test/browser/browser_ext_getViews.js
+++ b/browser/components/extensions/test/browser/browser_ext_getViews.js
@@ -135,22 +135,22 @@ add_task(function* () {
   }
 
   // The popup occasionally closes prematurely if we open it immediately here.
   // I'm not sure what causes it to close (it's something internal, and seems to
   // be focus-related, but it's not caused by JS calling hidePopup), but even a
   // short timeout seems to consistently fix it.
   yield new Promise(resolve => win1.setTimeout(resolve, 10));
 
-  yield triggerPopup(win1, function*() {
+  yield triggerPopup(win1, function* () {
     yield checkViews("background", 2, 1);
     yield checkViews("popup", 2, 1);
   });
 
-  yield triggerPopup(win2, function*() {
+  yield triggerPopup(win2, function* () {
     yield checkViews("background", 2, 1);
     yield checkViews("popup", 2, 1);
   });
 
   info("checking counts after popups");
 
   yield checkViews("background", 2, 0);
 
@@ -160,25 +160,25 @@ add_task(function* () {
   yield extension.awaitMessage("closed");
 
   info("one tab closed, one remains");
 
   yield checkViews("background", 1, 0);
 
   info("opening win1 popup");
 
-  yield triggerPopup(win1, function*() {
+  yield triggerPopup(win1, function* () {
     yield checkViews("background", 1, 1);
     yield checkViews("tab", 1, 1);
     yield checkViews("popup", 1, 1);
   });
 
   info("opening win2 popup");
 
-  yield triggerPopup(win2, function*() {
+  yield triggerPopup(win2, function* () {
     yield checkViews("background", 1, 1);
     yield checkViews("tab", 1, 1);
     yield checkViews("popup", 1, 1);
   });
 
   yield extension.unload();
 
   yield BrowserTestUtils.closeWindow(win1);
--- a/browser/components/extensions/test/browser/file_popup_api_injection_a.html
+++ b/browser/components/extensions/test/browser/file_popup_api_injection_a.html
@@ -1,9 +1,10 @@
 <!DOCTYPE html>
 <html>
 <head>
   <meta charset="utf-8">
   <script type="application/javascript">
+    "use strict";
     throw new Error(`WebExt Privilege Escalation: BrowserAction: typeof(browser) = ${typeof(browser)}`);
   </script>
 </head>
 </html>
--- a/browser/components/extensions/test/browser/file_popup_api_injection_b.html
+++ b/browser/components/extensions/test/browser/file_popup_api_injection_b.html
@@ -1,9 +1,10 @@
 <!DOCTYPE html>
 <html>
 <head>
   <meta charset="utf-8">
   <script type="application/javascript">
+    "use strict";
     throw new Error(`WebExt Privilege Escalation: PageAction: typeof(browser) = ${typeof(browser)}`);
   </script>
 </head>
 </html>
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -73,20 +73,18 @@ function getBrowserActionWidget(extensio
   return CustomizableUI.getWidget(makeWidgetId(extension.id) + "-browser-action");
 }
 
 function getBrowserActionPopup(extension, win = window) {
   let group = getBrowserActionWidget(extension);
 
   if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
     return win.document.getElementById("customizationui-widget-panel");
-  } else {
-    return win.PanelUI.panel;
   }
-  return null;
+  return win.PanelUI.panel;
 }
 
 var clickBrowserAction = Task.async(function* (extension, win = window) {
   let group = getBrowserActionWidget(extension);
   let widget = group.forWindow(win);
 
   if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
     ok(!widget.overflowed, "Expect widget not to be overflowed");
--- a/toolkit/components/extensions/.eslintrc
+++ b/toolkit/components/extensions/.eslintrc
@@ -79,16 +79,19 @@
     "generator-star-spacing": [2, {"before": false, "after": true}],
 
     // Two space indent
     "indent": [2, 2, {"SwitchCase": 1}],
 
     // Space after colon not before in property declarations
     "key-spacing": [2, {"beforeColon": false, "afterColon": true, "mode": "minimum"}],
 
+    // Require spaces before and after finally, catch, etc.
+    "keyword-spacing": 2,
+
     // Unix linebreaks
     "linebreak-style": [2, "unix"],
 
     // Always require parenthesis for new calls
     "new-parens": 2,
 
     // Use [] instead of Array()
     "no-array-constructor": 2,
@@ -97,19 +100,16 @@
     "no-dupe-args": 2,
 
     // No duplicate keys in object declarations
     "no-dupe-keys": 2,
 
     // No duplicate cases in switch statements
     "no-duplicate-case": 2,
 
-    // No labels
-    // "no-labels": 2,
-
     // If an if block ends with a return no need for an else block
     // "no-else-return": 2,
 
     // Disallow empty statements. This will report an error for:
     // try { something(); } catch (e) {}
     // but will not report it for:
     // try { something(); } catch (e) { /* Silencing the error because ...*/ }
     // which is a valid use case.
@@ -202,25 +202,19 @@
     "semi": [2, "always"],
 
     // Require space before blocks
     "space-before-blocks": 2,
 
     // Never use spaces before function parentheses
     "space-before-function-paren": [2, {"anonymous": "never", "named": "never"}],
 
-    // Require spaces before finally, catch, etc.
-    "space-before-keywords": [2, "always"],
-
     // Require spaces around operators, except for a|0.
     "space-infix-ops": [2, {"int32Hint": true}],
 
-    // Require spaces after return, throw and case
-    "space-return-throw-case": 2,
-
     // ++ and -- should not need spacing
     "space-unary-ops": [1, {"nonwords": false}],
 
     // No comparisons to NaN
     "use-isnan": 2,
 
     // Only check typeof against valid results
     "valid-typeof": 2,
@@ -316,19 +310,16 @@
     "no-debugger": 2,
 
     // Disallow deletion of variables (deleting properties is fine).
     "no-delete-var": 2,
 
     // Allow division operators explicitly at beginning of regular expression.
     "no-div-regex": 0,
 
-    // Disallow use of labels for anything other then loops and switches.
-    "no-empty-label": 2,
-
     // Disallow use of eval(). We have other APIs to evaluate code in content.
     "no-eval": 2,
 
     // Disallow adding to native types
     "no-extend-native": 2,
 
     // Disallow unnecessary function binding.
     "no-extra-bind": 2,
@@ -340,16 +331,19 @@
     "no-fallthrough": 2,
 
     // Allow the use of leading or trailing decimal points in numeric literals.
     "no-floating-decimal": 0,
 
     // Allow comments inline after code.
     "no-inline-comments": 0,
 
+    // Disallow use of labels for anything other then loops and switches.
+    "no-labels": [2, { "allowLoop": true }],
+
     // Disallow use of multiline strings (use template strings instead).
     "no-multi-str": 1,
 
     // Disallow multiple empty lines.
     "no-multiple-empty-lines": [1, {"max": 2}],
 
     // Allow reassignment of function parameters.
     "no-param-reassign": 0,
@@ -441,19 +435,16 @@
 
     // Enforce spacing after semicolons.
     "semi-spacing": [2, {"before": false, "after": true}],
 
     // Don't require to sort variables within the same declaration block.
     // Anyway, one-var is disabled.
     "sort-vars": 0,
 
-    // Require a space after keywords.
-    "space-after-keywords": [2, "always"],
-
     // Require a space immediately following the // in a line comment.
     "spaced-comment": [2, "always"],
 
     // Require "use strict" to be defined globally in the script.
     "strict": [2, "global"],
 
     // Warn about invalid JSDoc comments.
     "valid-jsdoc": 0,
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -541,17 +541,17 @@ DocumentManager = {
       return Promise.all(promises);
     }
     if (promises.length > 1) {
       return Promise.reject({message: `Internal error: Script matched multiple windows`});
     }
     return promises[0];
   },
 
-  enumerateWindows: function*(docShell) {
+  enumerateWindows: function* (docShell) {
     let window = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIDOMWindow);
     yield window;
 
     for (let i = 0; i < docShell.childCount; i++) {
       let child = docShell.getChildAt(i).QueryInterface(Ci.nsIDocShell);
       yield* this.enumerateWindows(child);
     }
--- a/toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_download.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_download.html
@@ -199,17 +199,17 @@ add_task(function* test_downloads() {
     is(msg.status, "error", "downloads.download() fails with back-references");
     is(msg.errmsg, "filename must not contain back-references (..)", "error message for back-references is correct");
   });
 
   yield extension.unload();
 });
 
 // check for leftover files in the download directory
-add_task(function*() {
+add_task(function* () {
   let entries = downloadDir.directoryEntries;
   while (entries.hasMoreElements()) {
     let entry = entries.getNext().QueryInterface(Ci.nsIFile);
     ok(false, `Leftover file ${entry.path} in download directory`);
     entry.remove(false);
   }
 
   downloadDir.remove(false);
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html
@@ -500,14 +500,14 @@ function* test_once(skipCompleted) {
   compareLists(recorded.error, expected_error, "error");
   compareLists(recorded.completed, expected_complete, "completed");
 
   yield extension.unload();
   info("webrequest extension unloaded");
 }
 
 // Run the test twice to make sure it works with caching.
-add_task(function*() { yield test_once(false); });
-add_task(function*() { yield test_once(true); });
+add_task(function* () { yield test_once(false); });
+add_task(function* () { yield test_once(true); });
 </script>
 
 </body>
 </html>