Bug 1336070 - Enable eslint no-undef for browser/, apart from components/ and base/content/. r=mossop
☠☠ backed out by fd0fc3404d16 ☠ ☠
authorMark Banner <standard8@mozilla.com>
Thu, 02 Feb 2017 09:08:42 +0000
changeset 332407 fc7f502a43a10c0f19f700a33c5d31c6c455bebb
parent 332406 c34aa52307299c37a214ae2a03ea8d5ac15abc1f
child 332408 e2486eb5bb766a536f5fa367ab809173a6195cc4
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1336070
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1336070 - Enable eslint no-undef for browser/, apart from components/ and base/content/. r=mossop MozReview-Commit-ID: CJtpm8zlLxa
browser/.eslintrc.js
browser/base/.eslintrc.js
browser/components/.eslintrc.js
browser/extensions/pocket/content/main.js
browser/extensions/presentation/bootstrap.js
browser/extensions/shield-recipe-client/lib/CleanupManager.jsm
browser/extensions/webcompat-reporter/bootstrap.js
browser/extensions/webcompat-reporter/content/WebCompatReporter.jsm
browser/extensions/webcompat-reporter/content/tab-frame.js
browser/extensions/webcompat-reporter/content/wc-frame.js
browser/extensions/webcompat/test/.eslintrc.js
browser/modules/test/browser_NetworkPrioritizer.js
browser/modules/test/contentSearch.js
tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- a/browser/.eslintrc.js
+++ b/browser/.eslintrc.js
@@ -2,11 +2,11 @@
 
 module.exports = {
   "extends": [
     "../toolkit/.eslintrc.js"
   ],
 
   "rules": {
     "no-shadow": "error",
-    "no-undef": "off"
+    "no-undef": "error"
   }
 };
--- a/browser/base/.eslintrc.js
+++ b/browser/base/.eslintrc.js
@@ -1,4 +1,7 @@
 "use strict";
 
 module.exports = {
+  rules: {
+    "no-undef": "off"
+  }
 };
new file mode 100644
--- /dev/null
+++ b/browser/components/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  rules: {
+    "no-undef": "off"
+  }
+};
--- a/browser/extensions/pocket/content/main.js
+++ b/browser/extensions/pocket/content/main.js
@@ -37,16 +37,17 @@
 
 // TODO : Get the toolbar icons from Firefox's build (Nikki needs to give us a red saved icon)
 // TODO : [needs clarificaiton from Fx] Firefox's plan was to hide Pocket from context menus until the user logs in. Now that it's an extension I'm wondering if we still need to do this.
 // TODO : [needs clarificaiton from Fx] Reader mode (might be a something they need to do since it's in html, need to investigate their code)
 // TODO : [needs clarificaiton from Fx] Move prefs within pktApi.s to sqlite or a local file so it's not editable (and is safer)
 // TODO : [nice to have] - Immediately save, buffer the actions in a local queue and send (so it works offline, works like our native extensions)
 
 /* eslint-disable no-shadow */
+/* eslint "mozilla/import-browserjs-globals": "error" */
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode",
   "resource://gre/modules/ReaderMode.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "pktApi",
   "chrome://pocket/content/pktApi.jsm");
--- a/browser/extensions/presentation/bootstrap.js
+++ b/browser/extensions/presentation/bootstrap.js
@@ -53,32 +53,34 @@ Factory.prototype = {
   },
 };
 
 var Presentation = {
   // PUBLIC APIs
   init() {
     log("init");
     // Register PresentationDevicePrompt into a XPCOM component.
-    Cu.import(PRESENTATION_DEVICE_PROMPT_PATH);
+    let {PresentationDevicePrompt} = Cu.import(PRESENTATION_DEVICE_PROMPT_PATH, {});
+    this.PresentationDevicePrompt = PresentationDevicePrompt;
     this._register();
   },
 
   uninit() {
     log("uninit");
     // Unregister PresentationDevicePrompt XPCOM component.
     this._unregister();
+    delete this.PresentationDevicePrompt;
     Cu.unload(PRESENTATION_DEVICE_PROMPT_PATH);
   },
 
   // PRIVATE APIs
   _register() {
     log("_register");
     this._devicePromptFactory = new Factory();
-    this._devicePromptFactory.register(PresentationDevicePrompt);
+    this._devicePromptFactory.register(this.PresentationDevicePrompt);
   },
 
   _unregister() {
     log("_unregister");
     this._devicePromptFactory.unregister();
     delete this._devicePromptFactory;
   },
 };
--- a/browser/extensions/shield-recipe-client/lib/CleanupManager.jsm
+++ b/browser/extensions/shield-recipe-client/lib/CleanupManager.jsm
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const {utils: Cu} = Components;
+
 this.EXPORTED_SYMBOLS = ["CleanupManager"];
 
 const cleanupHandlers = new Set();
 
 this.CleanupManager = {
   addCleanupHandler(handler) {
     cleanupHandlers.add(handler);
   },
--- a/browser/extensions/webcompat-reporter/bootstrap.js
+++ b/browser/extensions/webcompat-reporter/bootstrap.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* global APP_SHUTDOWN:false */
+
 let { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const WEBCOMPATREPORTER_JSM = "chrome://webcompat-reporter/content/WebCompatReporter.jsm";
 
 XPCOMUtils.defineLazyModuleGetter(this, "WebCompatReporter",
--- a/browser/extensions/webcompat-reporter/content/WebCompatReporter.jsm
+++ b/browser/extensions/webcompat-reporter/content/WebCompatReporter.jsm
@@ -26,17 +26,18 @@ const TABLISTENER_JSM = "chrome://webcom
 
 let WebCompatReporter = {
   get endpoint() {
     return Services.urlFormatter.formatURLPref(
       "extensions.webcompat-reporter.newIssueEndpoint");
   },
 
   init() {
-    Cu.import(TABLISTENER_JSM);
+    let TabListener = Cu.import(TABLISTENER_JSM, {});
+    this.TabListener = TabListener;
 
     let styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"]
       .getService(Ci.nsIStyleSheetService);
     this._sheetType = styleSheetService.AUTHOR_SHEET;
     this._cachedSheet = styleSheetService.preloadSheet(wcStyleURI,
                                                        this._sheetType);
 
     CustomizableUI.createWidget({
@@ -56,17 +57,17 @@ let WebCompatReporter = {
   },
 
   onWindowOpened(win) {
     // Attach stylesheet for the button icon.
     win.QueryInterface(Ci.nsIInterfaceRequestor)
       .getInterface(Ci.nsIDOMWindowUtils)
       .addSheet(this._cachedSheet, this._sheetType);
     // Attach listeners to new window.
-    win._webcompatReporterTabListener = new TabListener(win);
+    win._webcompatReporterTabListener = new this.TabListener(win);
   },
 
   onWindowClosed(win) {
     if (win._webcompatReporterTabListener) {
       win._webcompatReporterTabListener.removeListeners();
       delete win._webcompatReporterTabListener;
     }
   },
@@ -78,16 +79,17 @@ let WebCompatReporter = {
       this.onWindowClosed(win);
 
       win.QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIDOMWindowUtils)
         .removeSheet(wcStyleURI, this._sheetType);
     }
 
     CustomizableUI.removeListener(this);
+    delete this.TabListener;
     Cu.unload(TABLISTENER_JSM);
   },
 
   // This method injects a framescript that should send back a screenshot blob
   // of the top-level window of the currently selected tab, resolved as a
   // Promise.
   getScreenshot(gBrowser) {
     const FRAMESCRIPT = "chrome://webcompat-reporter/content/tab-frame.js";
--- a/browser/extensions/webcompat-reporter/content/tab-frame.js
+++ b/browser/extensions/webcompat-reporter/content/tab-frame.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* global content:false, sendAsyncMessage:false */
+
 let { utils: Cu } = Components;
 
 const TABDATA_MESSAGE = "WebCompat:SendTabData";
 
 let getScreenshot = function(win) {
   return new Promise(resolve => {
     let url = win.location.href;
     try {
--- a/browser/extensions/webcompat-reporter/content/wc-frame.js
+++ b/browser/extensions/webcompat-reporter/content/wc-frame.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* global content:false, addMessageListener:false, removeMessageListener: false */
+
 let { utils: Cu } = Components;
 
 const SCREENSHOT_MESSAGE = "WebCompat:SendScreenshot";
 
 addMessageListener(SCREENSHOT_MESSAGE, function handleMessage(message) {
   removeMessageListener(SCREENSHOT_MESSAGE, handleMessage);
   // postMessage the screenshot blob from a content Sandbox so message event.origin
   // is what we expect on the client-side (i.e., https://webcompat.com)
new file mode 100644
--- /dev/null
+++ b/browser/extensions/webcompat/test/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "../../../../testing/mochitest/browser.eslintrc.js"
+  ]
+};
--- a/browser/modules/test/browser_NetworkPrioritizer.js
+++ b/browser/modules/test/browser_NetworkPrioritizer.js
@@ -14,34 +14,36 @@ const DELTA = NORMAL - LOW; // lower val
 
 // Test helper functions.
 // getPriority and setPriority can take a tab or a Browser
 function* getPriority(aBrowser) {
   if (aBrowser.localName == "tab")
     aBrowser = aBrowser.linkedBrowser;
 
   return yield ContentTask.spawn(aBrowser, null, function* () {
-    return docShell.QueryInterface(Components.interfaces.nsIWebNavigation)
-                   .QueryInterface(Components.interfaces.nsIDocumentLoader)
-                   .loadGroup
-                   .QueryInterface(Components.interfaces.nsISupportsPriority)
-                   .priority;
+    return content.document.docShell
+      .QueryInterface(Components.interfaces.nsIWebNavigation)
+      .QueryInterface(Components.interfaces.nsIDocumentLoader)
+      .loadGroup
+      .QueryInterface(Components.interfaces.nsISupportsPriority)
+      .priority;
   });
 }
 
 function* setPriority(aBrowser, aPriority) {
   if (aBrowser.localName == "tab")
     aBrowser = aBrowser.linkedBrowser;
 
   yield ContentTask.spawn(aBrowser, aPriority, function* (contentPriority) {
-    docShell.QueryInterface(Components.interfaces.nsIWebNavigation)
-                                    .QueryInterface(Components.interfaces.nsIDocumentLoader)
-                                    .loadGroup
-                                    .QueryInterface(Ci.nsISupportsPriority)
-                                    .priority = contentPriority;
+    content.document.docShell
+      .QueryInterface(Components.interfaces.nsIWebNavigation)
+      .QueryInterface(Components.interfaces.nsIDocumentLoader)
+      .loadGroup
+      .QueryInterface(Ci.nsISupportsPriority)
+      .priority = contentPriority;
   });
 }
 
 function* isWindowState(aWindow, aTabPriorities) {
   let browsers = aWindow.gBrowser.browsers;
   // Make sure we have the right number of tabs & priorities
   is(browsers.length, aTabPriorities.length,
      "Window has expected number of tabs");
--- a/browser/modules/test/contentSearch.js
+++ b/browser/modules/test/contentSearch.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* global addMessageListener:false, sendAsyncMessage:false, XPCOMUtils */
+
 const TEST_MSG = "ContentSearchTest";
 const SERVICE_EVENT_TYPE = "ContentSearchService";
 const CLIENT_EVENT_TYPE = "ContentSearchClient";
 
 // Forward events from the in-content service to the test.
 content.addEventListener(SERVICE_EVENT_TYPE, event => {
   // The event dispatch code in content.js clones the event detail into the
   // content scope. That's generally the right thing, but causes us to end
@@ -33,18 +35,18 @@ addMessageListener(TEST_MSG, msg => {
     new content.CustomEvent(CLIENT_EVENT_TYPE, {
       detail: msg.data,
     })
   );
 });
 
 function waitForLoadAndStopIt(expectedURL, callback) {
   let Ci = Components.interfaces;
-  let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
-                            .getInterface(Ci.nsIWebProgress);
+  let webProgress = content.document.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                                             .getInterface(Ci.nsIWebProgress);
   let listener = {
     onStateChange(webProg, req, flags, status) {
       if (req instanceof Ci.nsIChannel) {
         let url = req.originalURI.spec;
         dump("waitForLoadAndStopIt: onStateChange " + url + "\n");
         let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
                        Ci.nsIWebProgressListener.STATE_START;
         if ((flags & docStart) && webProg.isTopLevel && url == expectedURL) {
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
@@ -49,23 +49,26 @@ const SCRIPTS = [
   "browser/base/content/browser-trackingprotection.js",
   "browser/base/content/browser-data-submission-info-bar.js",
   "browser/base/content/browser-fxaccounts.js"
 ];
 
 module.exports = function(context) {
   return {
     Program: function(node) {
-      if (helpers.getTestType(this) != "browser" &&
-          !helpers.getIsHeadFile(this)) {
+      let filepath = helpers.getAbsoluteFilePath(context);
+      let root = helpers.getRootDir(filepath);
+      let relativepath = path.relative(root, filepath);
+
+      if ((helpers.getTestType(this) != "browser" &&
+          !helpers.getIsHeadFile(this)) &&
+          !relativepath.includes("content")) {
         return;
       }
 
-      let filepath = helpers.getAbsoluteFilePath(context);
-      let root = helpers.getRootDir(filepath);
       for (let script of SCRIPTS) {
         let fileName = path.join(root, script);
         try {
           let newGlobals = globals.getGlobalsForFile(fileName);
           helpers.addGlobals(newGlobals, context.getScope());
         } catch (e) {
           context.report(
             node,
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -1,11 +1,11 @@
 {
   "name": "eslint-plugin-mozilla",
-  "version": "0.2.17",
+  "version": "0.2.18",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],