Bug 1228628 - Add a minimal .eslintrc configuration for browser and start linting a few browser files with basic rules. r=Mossop
authorMark Banner <standard8@mozilla.com>
Mon, 30 Nov 2015 11:42:25 +0000
changeset 274503 58e64709ae1d79680f653d38b1f977dd384bf05a
parent 274502 cc2af13f040c5aad6eb2e4ec792162f38a39ca93
child 274504 37f3907090aa0abe642f6a1210915c98694fcae8
push id16450
push usermbanner@mozilla.com
push dateMon, 30 Nov 2015 11:43:31 +0000
treeherderfx-team@58e64709ae1d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1228628
milestone45.0a1
Bug 1228628 - Add a minimal .eslintrc configuration for browser and start linting a few browser files with basic rules. r=Mossop
.eslintignore
.eslintrc
browser/.eslintrc
browser/components/newtab/tests/xpcshell/test_RemoteNewTabUtils.js
browser/components/search/test/browser_426329.js
browser/components/search/test/browser_healthreport.js
browser/experiments/Experiments.jsm
browser/extensions/loop/.eslintignore
browser/extensions/loop/.eslintrc
devtools/.eslintrc
mobile/android/.eslintrc
--- a/.eslintignore
+++ b/.eslintignore
@@ -53,28 +53,36 @@ webapprt/**
 widget/**
 xpcom/**
 xpfe/**
 xulrunner/**
 
 # browser/ exclusions
 browser/app/**
 browser/base/**
-browser/branding/**
-browser/components/**
-browser/config/**
-browser/docs/**
+browser/components/customizableui/**
+browser/components/downloads/**
+browser/components/feeds/**
+browser/components/migration/**
+browser/components/*.js
+browser/components/places/**
+browser/components/pocket/**
+browser/components/preferences/**
+browser/components/privatebrowsing/**
+browser/components/sessionstore/**
+browser/components/shell/**
+browser/components/tabview/**
+browser/components/translation/**
+browser/components/uitour/**
 browser/experiments/**
 browser/extensions/pdfjs/**
 browser/extensions/shumway/**
 browser/fuel/**
-browser/installer/**
 browser/locales/**
 browser/modules/**
-browser/themes/**
 
 # Loop specific exclusions
 
 # This file currently uses a non-standard (and not on a standards track)
 # if statement within catch.
 browser/extensions/loop/content/modules/MozLoopWorker.js
 # This file currently uses es7 features eslint issue:
 # https://github.com/eslint/espree/issues/125
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,5 +1,9 @@
 {
+  // When adding items to this file please check for effects on sub-directories.
   "plugins": [
     "mozilla"
-  ]
+  ],
+  "env": {
+    "es6": true
+  },
 }
new file mode 100644
--- /dev/null
+++ b/browser/.eslintrc
@@ -0,0 +1,6 @@
+{
+  // When adding items to this file please check for effects on sub-directories.
+  "rules": {
+    "eol-last": 2,
+  }
+}
--- a/browser/components/newtab/tests/xpcshell/test_RemoteNewTabUtils.js
+++ b/browser/components/newtab/tests/xpcshell/test_RemoteNewTabUtils.js
@@ -8,17 +8,17 @@ Cu.import("resource:///modules/RemoteNew
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 function run_test() {
   run_next_test();
 }
 
-add_task(function validCacheMidPopulation() {
+add_task(function* validCacheMidPopulation() {
   let expectedLinks = makeLinks(0, 3, 1);
 
   let provider = new TestProvider(done => done(expectedLinks));
   provider.maxNumLinks = expectedLinks.length;
 
   RemoteNewTabUtils.initWithoutProviders();
   RemoteNewTabUtils.links.addProvider(provider);
   let promise = new Promise(resolve => RemoteNewTabUtils.links.populateCache(resolve));
@@ -31,17 +31,17 @@ add_task(function validCacheMidPopulatio
   yield promise;
 
   // Once the cache is populated, we get the expected results
   do_check_true(RemoteNewTabUtils.isTopSiteGivenProvider("example1.com", provider));
   do_check_links(RemoteNewTabUtils.getProviderLinks(provider), expectedLinks);
   RemoteNewTabUtils.links.removeProvider(provider);
 });
 
-add_task(function notifyLinkDelete() {
+add_task(function* notifyLinkDelete() {
   let expectedLinks = makeLinks(0, 3, 1);
 
   let provider = new TestProvider(done => done(expectedLinks));
   provider.maxNumLinks = expectedLinks.length;
 
   RemoteNewTabUtils.initWithoutProviders();
   RemoteNewTabUtils.links.addProvider(provider);
   yield new Promise(resolve => RemoteNewTabUtils.links.populateCache(resolve));
@@ -90,17 +90,17 @@ add_task(function populatePromise() {
 
   RemoteNewTabUtils.links.populateProviderCache(provider, () => {});
   RemoteNewTabUtils.links.populateProviderCache(provider, () => {
     do_check_links(RemoteNewTabUtils.links.getLinks(), expectedLinks);
     RemoteNewTabUtils.links.removeProvider(provider);
   });
 });
 
-add_task(function isTopSiteGivenProvider() {
+add_task(function* isTopSiteGivenProvider() {
   let expectedLinks = makeLinks(0, 10, 2);
 
   // The lowest 2 frecencies have the same base domain.
   expectedLinks[expectedLinks.length - 2].url = expectedLinks[expectedLinks.length - 1].url + "Test";
 
   let provider = new TestProvider(done => done(expectedLinks));
   provider.maxNumLinks = expectedLinks.length;
 
@@ -129,17 +129,17 @@ add_task(function isTopSiteGivenProvider
 
   // Our count reached 0 for the example2.com domain so it's no longer a frecent site.
   do_check_eq(RemoteNewTabUtils.isTopSiteGivenProvider("example5.com", provider), true);
   do_check_eq(RemoteNewTabUtils.isTopSiteGivenProvider("example2.com", provider), false);
 
   RemoteNewTabUtils.links.removeProvider(provider);
 });
 
-add_task(function multipleProviders() {
+add_task(function* multipleProviders() {
   // Make each provider generate RemoteNewTabUtils.links.maxNumLinks links to check
   // that no more than maxNumLinks are actually returned in the merged list.
   let evenLinks = makeLinks(0, 2 * RemoteNewTabUtils.links.maxNumLinks, 2);
   let evenProvider = new TestProvider(done => done(evenLinks));
   let oddLinks = makeLinks(0, 2 * RemoteNewTabUtils.links.maxNumLinks - 1, 2);
   let oddProvider = new TestProvider(done => done(oddLinks));
 
   RemoteNewTabUtils.initWithoutProviders();
@@ -154,17 +154,17 @@ add_task(function multipleProviders() {
                                 1);
   do_check_eq(links.length, RemoteNewTabUtils.links.maxNumLinks);
   do_check_links(links, expectedLinks);
 
   RemoteNewTabUtils.links.removeProvider(evenProvider);
   RemoteNewTabUtils.links.removeProvider(oddProvider);
 });
 
-add_task(function changeLinks() {
+add_task(function* changeLinks() {
   let expectedLinks = makeLinks(0, 20, 2);
   let provider = new TestProvider(done => done(expectedLinks));
 
   RemoteNewTabUtils.initWithoutProviders();
   RemoteNewTabUtils.links.addProvider(provider);
 
   yield new Promise(resolve => RemoteNewTabUtils.links.populateCache(resolve));
 
@@ -212,17 +212,17 @@ add_task(function changeLinks() {
   yield RemoteNewTabUtils.links._providers.get(provider).populatePromise;
 
   // RemoteNewTabUtils.links will now repopulate its cache
   do_check_links(RemoteNewTabUtils.links.getLinks(), expectedLinks);
 
   RemoteNewTabUtils.links.removeProvider(provider);
 });
 
-add_task(function oneProviderAlreadyCached() {
+add_task(function* oneProviderAlreadyCached() {
   let links1 = makeLinks(0, 10, 1);
   let provider1 = new TestProvider(done => done(links1));
 
   RemoteNewTabUtils.initWithoutProviders();
   RemoteNewTabUtils.links.addProvider(provider1);
 
   yield new Promise(resolve => RemoteNewTabUtils.links.populateCache(resolve));
   do_check_links(RemoteNewTabUtils.links.getLinks(), links1);
@@ -233,17 +233,17 @@ add_task(function oneProviderAlreadyCach
 
   yield new Promise(resolve => RemoteNewTabUtils.links.populateCache(resolve));
   do_check_links(RemoteNewTabUtils.links.getLinks(), links2.concat(links1));
 
   RemoteNewTabUtils.links.removeProvider(provider1);
   RemoteNewTabUtils.links.removeProvider(provider2);
 });
 
-add_task(function newLowRankedLink() {
+add_task(function* newLowRankedLink() {
   // Init a provider with 10 links and make its maximum number also 10.
   let links = makeLinks(0, 10, 1);
   let provider = new TestProvider(done => done(links));
   provider.maxNumLinks = links.length;
 
   RemoteNewTabUtils.initWithoutProviders();
   RemoteNewTabUtils.links.addProvider(provider);
 
--- a/browser/components/search/test/browser_426329.js
+++ b/browser/components/search/test/browser_426329.js
@@ -143,134 +143,134 @@ function* prepareTest() {
     gURLBar.focus();
     searchBar.focus();
   } else {
     deferred.resolve();
   }
   return deferred.promise;
 }
 
-add_task(function testSetupEngine() {
+add_task(function* testSetupEngine() {
   yield promiseSetEngine();
 });
 
-add_task(function testReturn() {
+add_task(function* testReturn() {
   yield prepareTest();
   EventUtils.synthesizeKey("VK_RETURN", {});
   let event = yield promiseOnLoad();
 
   is(gBrowser.tabs.length, preTabNo, "Return key did not open new tab");
   is(event.originalTarget, preSelectedBrowser.contentDocument,
      "Return key loaded results in current tab");
   is(event.originalTarget.URL, expectedURL(searchBar.value), "testReturn opened correct search page");
 });
 
-add_task(function testAltReturn() {
+add_task(function* testAltReturn() {
   yield prepareTest();
   EventUtils.synthesizeKey("VK_RETURN", { altKey: true });
   let event = yield promiseOnLoad();
 
   is(gBrowser.tabs.length, preTabNo + 1, "Alt+Return key added new tab");
   isnot(event.originalTarget, preSelectedBrowser.contentDocument,
         "Alt+Return key loaded results in new tab");
   is(event.originalTarget, gBrowser.contentDocument,
      "Alt+Return key loaded results in foreground tab");
   is(event.originalTarget.URL, expectedURL(searchBar.value), "testAltReturn opened correct search page");
 });
 
 //Shift key has no effect for now, so skip it
-add_task(function testShiftAltReturn() {
+add_task(function* testShiftAltReturn() {
   return;
 
   yield prepareTest();
   EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true, altKey: true });
   let event = yield promiseOnLoad();
 
   is(gBrowser.tabs.length, preTabNo + 1, "Shift+Alt+Return key added new tab");
   isnot(event.originalTarget, preSelectedBrowser.contentDocument,
         "Shift+Alt+Return key loaded results in new tab");
   isnot(event.originalTarget, gBrowser.contentDocument,
         "Shift+Alt+Return key loaded results in background tab");
   is(event.originalTarget.URL, expectedURL(searchBar.value), "testShiftAltReturn opened correct search page");
 });
 
-add_task(function testLeftClick() {
+add_task(function* testLeftClick() {
   yield prepareTest();
   simulateClick({ button: 0 }, searchButton);
   let event = yield promiseOnLoad();
   is(gBrowser.tabs.length, preTabNo, "LeftClick did not open new tab");
   is(event.originalTarget, preSelectedBrowser.contentDocument,
      "LeftClick loaded results in current tab");
   is(event.originalTarget.URL, expectedURL(searchBar.value), "testLeftClick opened correct search page");
 });
 
-add_task(function testMiddleClick() {
+add_task(function* testMiddleClick() {
   yield prepareTest();
   simulateClick({ button: 1 }, searchButton);
   let event = yield promiseOnLoad();
   is(gBrowser.tabs.length, preTabNo + 1, "MiddleClick added new tab");
   isnot(event.originalTarget, preSelectedBrowser.contentDocument,
         "MiddleClick loaded results in new tab");
   is(event.originalTarget, gBrowser.contentDocument,
      "MiddleClick loaded results in foreground tab");
   is(event.originalTarget.URL, expectedURL(searchBar.value), "testMiddleClick opened correct search page");
 });
 
-add_task(function testShiftMiddleClick() {
+add_task(function* testShiftMiddleClick() {
   yield prepareTest();
   simulateClick({ button: 1, shiftKey: true }, searchButton);
   let event = yield promiseOnLoad();
   is(gBrowser.tabs.length, preTabNo + 1, "Shift+MiddleClick added new tab");
   isnot(event.originalTarget, preSelectedBrowser.contentDocument,
         "Shift+MiddleClick loaded results in new tab");
   isnot(event.originalTarget, gBrowser.contentDocument,
         "Shift+MiddleClick loaded results in background tab");
   is(event.originalTarget.URL, expectedURL(searchBar.value), "testShiftMiddleClick opened correct search page");
 });
 
-add_task(function testRightClick() {
+add_task(function* testRightClick() {
   preTabNo = gBrowser.tabs.length;
   content.location.href = "about:blank";
   simulateClick({ button: 2 }, searchButton);
   let deferred = Promise.defer();
   setTimeout(function() {
     is(gBrowser.tabs.length, preTabNo, "RightClick did not open new tab");
     is(gBrowser.currentURI.spec, "about:blank", "RightClick did nothing");
     deferred.resolve();
   }, 5000);
   yield deferred.promise;
   // The click in the searchbox focuses it, which opens the suggestion
   // panel. Clean up after ourselves.
   searchBar.textbox.popup.hidePopup();
 });
 
-add_task(function testSearchHistory() {
+add_task(function* testSearchHistory() {
   var textbox = searchBar._textbox;
   for (var i = 0; i < searchEntries.length; i++) {
     let count = yield countEntries(textbox.getAttribute("autocompletesearchparam"), searchEntries[i]);
     ok(count > 0, "form history entry '" + searchEntries[i] + "' should exist");
   }
 });
 
-add_task(function testAutocomplete() {
+add_task(function* testAutocomplete() {
   var popup = searchBar.textbox.popup;
   let popupShownPromise = promiseEvent(popup, "popupshown");
   searchBar.textbox.showHistoryPopup();
   yield popupShownPromise;
   checkMenuEntries(searchEntries);
 });
 
-add_task(function testClearHistory() {
+add_task(function* testClearHistory() {
   let controller = searchBar.textbox.controllers.getControllerForCommand("cmd_clearhistory")
   ok(controller.isCommandEnabled("cmd_clearhistory"), "Clear history command enabled");
   controller.doCommand("cmd_clearhistory");
   let count = yield countEntries();
   ok(count == 0, "History cleared");
 });
 
-add_task(function asyncCleanup() {
+add_task(function* asyncCleanup() {
   searchBar.value = "";
   while (gBrowser.tabs.length != 1) {
     gBrowser.removeTab(gBrowser.tabs[0], {animate: false});
   }
   content.location.href = "about:blank";
   yield promiseRemoveEngine();
 });
--- a/browser/components/search/test/browser_healthreport.js
+++ b/browser/components/search/test/browser_healthreport.js
@@ -101,9 +101,9 @@ function test() {
 }
 
 function resetPreferences() {
   let service = Components.classes["@mozilla.org/datareporting/service;1"]
                                   .getService(Components.interfaces.nsISupports)
                                   .wrappedJSObject;
   service.policy._prefs.resetBranch("datareporting.policy.");
   service.policy.dataSubmissionPolicyBypassNotification = true;
-}
\ No newline at end of file
+}
--- a/browser/experiments/Experiments.jsm
+++ b/browser/experiments/Experiments.jsm
@@ -139,29 +139,29 @@ function configureLogging() {
 }
 
 // Loads a JSON file using OS.file. file is a string representing the path
 // of the file to be read, options contains additional options to pass to
 // OS.File.read.
 // Returns a Promise resolved with the json payload or rejected with
 // OS.File.Error or JSON.parse() errors.
 function loadJSONAsync(file, options) {
-  return Task.spawn(function() {
+  return Task.spawn(function*() {
     let rawData = yield OS.File.read(file, options);
     // Read json file into a string
     let data;
     try {
       // Obtain a converter to read from a UTF-8 encoded input stream.
       let converter = new TextDecoder();
       data = JSON.parse(converter.decode(rawData));
     } catch (ex) {
       gLogger.error("Experiments: Could not parse JSON: " + file + " " + ex);
       throw ex;
     }
-    throw new Task.Result(data);
+    return data;
   });
 }
 
 function telemetryEnabled() {
   return gPrefsTelemetry.get(PREF_TELEMETRY_ENABLED, false);
 }
 
 // Returns a promise that is resolved with the AddonInstall for that URL.
deleted file mode 100644
--- a/browser/extensions/loop/.eslintignore
+++ /dev/null
@@ -1,35 +0,0 @@
-# This file currently uses a non-standard (and not on a standards track)
-# if statement within catch.
-content/modules/MozLoopWorker.js
-# This file currently uses es7 features eslint issue:
-# https://github.com/eslint/espree/issues/125
-content/modules/MozLoopAPI.jsm
-# Need to fix the configuration for this.
-bootstrap.js
-# Need to drop the preprocessing (bug 1212428)
-content/preferences/prefs.js
-# Libs we don't need to check
-content/panels/vendor
-content/shared/vendor
-standalone/content/libs
-standalone/node_modules
-# Libs we don't need to check
-test/shared/vendor
-# Coverage files
-test/coverage
-test/node_modules
-# These are generated react files that we don't need to check
-content/panels/js/conversation.js
-content/panels/js/conversationViews.js
-content/panels/js/panel.js
-content/panels/js/roomViews.js
-content/panels/js/feedbackViews.js
-content/shared/js/textChatView.js
-content/shared/js/linkifiedTextView.js
-content/shared/js/views.js
-standalone/content/js/standaloneRoomViews.js
-standalone/content/js/webapp.js
-ui/ui-showcase.js
-# Don't need to check the built tree
-standalone/dist
-
--- a/browser/extensions/loop/.eslintrc
+++ b/browser/extensions/loop/.eslintrc
@@ -1,21 +1,32 @@
 // Note: there are extra allowances for files used solely in Firefox desktop,
 // see content/js/.eslintrc and modules/.eslintrc
 {
   "plugins": [
     "react"
   ],
   "ecmaFeatures": {
+    // Allow these.
     "forOf": true,
     "jsx": true,
+    // Disallow due to content.
+    "arrowFunctions": false,
+    "blockBindings": false,
+    "destructuring": false,
+    "generators": false,
+    "objectLiteralShorthandMethods": false,
+    "restParams": false,
+    "spread": false,
+    "templateStrings": false,
   },
   "env": {
     "browser": true,
-    "mocha": true
+    "es6": false,
+    "mocha": true,
   },
   "extends": "eslint:recommended",
   "globals": {
     "_": false,
     "Backbone": false,
     "chai": false,
     "classNames": false,
     "console": false,
--- a/devtools/.eslintrc
+++ b/devtools/.eslintrc
@@ -1,12 +1,9 @@
 {
-  "env": {
-    "es6": true
-  },
   "globals": {
     "Cc": true,
     "Ci": true,
     "Components": true,
     "console": true,
     "Cr": true,
     "Cu": true,
     "devtools": true,
--- a/mobile/android/.eslintrc
+++ b/mobile/android/.eslintrc
@@ -1,11 +1,10 @@
 env:
     browser: true
-    es6: true
 
 globals:
     Components: false
 
     # TODO: Create custom rule for `Cu.import`
     AddonManager: false
     AppConstants: false
     Downloads: false