Bug 1594964 - Unify linting rules for test directories. r=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 05 Nov 2019 16:48:02 +1300
changeset 36613 cacce68c2d9a4eeb1110d30931455e502696c14b
parent 36612 46a75a66d88d7feee5b3492bb70a2246a217c8c1
child 36614 d5defac499ad2eaf03b571b3f8d82ea759ef523b
push id2534
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:52:51 +0000
treeherdercomm-beta@055c50840778 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspmorris
bugs1594964
Bug 1594964 - Unify linting rules for test directories. r=pmorris
.eslintrc.js
calendar/.eslintrc.js
calendar/test/browser/head.js
calendar/test/unit/.eslintrc.js
calendar/test/unit/head_consts.js
calendar/test/unit/test_extract.js
calendar/test/unit/test_freebusy_service.js
calendar/test/unit/test_itip_utils.js
calendar/test/unit/test_recur.js
mail/components/cloudfile/test/browser/.eslintrc.js
mail/components/enterprisepolicies/tests/browser/.eslintrc.js
mail/components/extensions/test/browser/.eslintrc.js
mail/components/extensions/test/xpcshell/.eslintrc.js
mailnews/db/gloda/test/unit/.eslintrc.js
mailnews/db/gloda/test/unit/head_gloda.js
mailnews/mime/jsmime/test/.eslintrc.js
mailnews/mime/jsmime/test/data/base64-1
mailnews/mime/jsmime/test/data/base64-2
mailnews/mime/jsmime/test/data/basic1
mailnews/mime/jsmime/test/data/bug505221
mailnews/mime/jsmime/test/data/bugmail11
mailnews/mime/jsmime/test/data/charsets
mailnews/mime/jsmime/test/data/message-encoded
mailnews/mime/jsmime/test/data/mime-torture
mailnews/mime/jsmime/test/data/multipart-base64-1
mailnews/mime/jsmime/test/data/multipart-base64-2
mailnews/mime/jsmime/test/data/multipart-base64-3
mailnews/mime/jsmime/test/data/multipart-complex1
mailnews/mime/jsmime/test/data/multipart-complex2
mailnews/mime/jsmime/test/data/multipart1
mailnews/mime/jsmime/test/data/multipart2
mailnews/mime/jsmime/test/data/multipart3
mailnews/mime/jsmime/test/data/multipart4
mailnews/mime/jsmime/test/data/multipartmalt-detach
mailnews/mime/jsmime/test/data/shift-jis-image
mailnews/mime/jsmime/test/head_xpcshell_glue.js
mailnews/mime/jsmime/test/mock_date.js
mailnews/mime/jsmime/test/test_custom_headers.js
mailnews/mime/jsmime/test/test_header.js
mailnews/mime/jsmime/test/test_header_emitter.js
mailnews/mime/jsmime/test/test_mime_tree.js
mailnews/mime/jsmime/test/test_structured_header_emitters.js
mailnews/mime/jsmime/test/test_structured_headers.js
mailnews/mime/jsmime/test/unit/data/base64-1
mailnews/mime/jsmime/test/unit/data/base64-2
mailnews/mime/jsmime/test/unit/data/basic1
mailnews/mime/jsmime/test/unit/data/bug505221
mailnews/mime/jsmime/test/unit/data/bugmail11
mailnews/mime/jsmime/test/unit/data/charsets
mailnews/mime/jsmime/test/unit/data/message-encoded
mailnews/mime/jsmime/test/unit/data/mime-torture
mailnews/mime/jsmime/test/unit/data/multipart-base64-1
mailnews/mime/jsmime/test/unit/data/multipart-base64-2
mailnews/mime/jsmime/test/unit/data/multipart-base64-3
mailnews/mime/jsmime/test/unit/data/multipart-complex1
mailnews/mime/jsmime/test/unit/data/multipart-complex2
mailnews/mime/jsmime/test/unit/data/multipart1
mailnews/mime/jsmime/test/unit/data/multipart2
mailnews/mime/jsmime/test/unit/data/multipart3
mailnews/mime/jsmime/test/unit/data/multipart4
mailnews/mime/jsmime/test/unit/data/multipartmalt-detach
mailnews/mime/jsmime/test/unit/data/shift-jis-image
mailnews/mime/jsmime/test/unit/head_xpcshell_glue.js
mailnews/mime/jsmime/test/unit/mock_date.js
mailnews/mime/jsmime/test/unit/test_custom_headers.js
mailnews/mime/jsmime/test/unit/test_header.js
mailnews/mime/jsmime/test/unit/test_header_emitter.js
mailnews/mime/jsmime/test/unit/test_mime_tree.js
mailnews/mime/jsmime/test/unit/test_structured_header_emitters.js
mailnews/mime/jsmime/test/unit/test_structured_headers.js
mailnews/mime/jsmime/test/unit/xpcshell.ini
mailnews/mime/jsmime/test/xpcshell.ini
mailnews/mime/moz.build
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -86,21 +86,24 @@ module.exports = {
       ...removeOverrides(xpcshellTestConfig),
       files: xpcshellTestPaths.map(path => `${path}**`),
       rules: {
         ...xpcshellTestConfig.rules,
         "func-names": "off",
       },
     },
     {
-      // If it is an xpcshell head file, we turn off global unused variable checks, as it
+      // If it is a test head file, we turn off global unused variable checks, as it
       // would require searching the other test files to know if they are used or not.
       // This would be expensive and slow, and it isn't worth it for head files.
       // We could get developers to declare as exported, but that doesn't seem worth it.
-      files: xpcshellTestPaths.map(path => `${path}head*.js`),
+      files: [
+        ...browserTestPaths.map(path => `${path}head*.js`),
+        ...xpcshellTestPaths.map(path => `${path}head*.js`),
+      ],
       rules: {
         "no-unused-vars": [
           "error",
           {
             args: "none",
             vars: "local",
           },
         ],
--- a/calendar/.eslintrc.js
+++ b/calendar/.eslintrc.js
@@ -516,10 +516,26 @@ module.exports = {
               set: "Set",
               date: "Date",
             },
             requireReturn: false,
           },
         ],
       },
     },
+    {
+      // If it is a test head file, we turn off global unused variable checks, as it
+      // would require searching the other test files to know if they are used or not.
+      // This would be expensive and slow, and it isn't worth it for head files.
+      // We could get developers to declare as exported, but that doesn't seem worth it.
+      files: ["test/**/head*.js"],
+      rules: {
+        "no-unused-vars": [
+          "error",
+          {
+            args: "none",
+            vars: "local",
+          },
+        ],
+      },
+    },
   ],
 };
--- a/calendar/test/browser/head.js
+++ b/calendar/test/browser/head.js
@@ -1,17 +1,12 @@
 /* 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/. */
 
-/* exported closeAddonsTab, closeCalendarTab, closeChatTab, closePreferencesTab, closeTasksTab,
-   openAddonsTab, openCalendarTab, openChatTab, openNewCalendarEventTab, openNewCalendarTaskTab,
-   openPreferencesTab, openTasksTab, selectCalendarEventTab, selectCalendarTaskTab,
-   selectFolderTab, setCalendarView */
-
 /* import-globals-from ../../base/content/calendar-views-utils.js */
 
 /* globals openOptionsDialog, openAddonsMgr */
 
 async function openCalendarTab() {
   let tabmail = document.getElementById("tabmail");
   let calendarMode = tabmail.tabModes.calendar;
 
deleted file mode 100644
--- a/calendar/test/unit/.eslintrc.js
+++ /dev/null
@@ -1,21 +0,0 @@
-"use strict";
-
-module.exports = {
-  extends: ["plugin:mozilla/xpcshell-test"],
-  rules: {
-    // Allow non-camelcase so that run_test doesn't produce a warning.
-    camelcase: 0,
-    // Allow using undefined variables so that tests can refer to functions
-    // and variables defined in head.js files, without having to maintain a
-    // list of globals in each .eslintrc file.
-    // Note that bug 1168340 will eventually help auto-registering globals
-    // from head.js files.
-    "no-undef": 0,
-    "block-scoped-var": 0,
-    // Allow run_test to be unused in xpcshell
-    "no-unused-vars": [2, { vars: "all", args: "none", varsIgnorePattern: "run_test" }],
-
-    // Allow function names, because they are useful for add_test/add_task
-    "func-names": 0,
-  },
-};
--- a/calendar/test/unit/head_consts.js
+++ b/calendar/test/unit/head_consts.js
@@ -1,17 +1,12 @@
 /* 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/. */
 
-/* exported do_calendar_startup, do_load_calmgr, do_load_timezoneservice, readJSONFile,
- *          ics_unfoldline, dedent, compareItemsSpecific, getStorageCal, getMemoryCal,
- *          createTodoFromIcalString, createEventFromIcalString, createDate, Cc, Ci, Cr, Cu
- */
-
 var { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
 
 var { updateAppInfo } = ChromeUtils.import("resource://testing-common/AppInfo.jsm");
 
 ChromeUtils.defineModuleGetter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
 
@@ -305,15 +300,15 @@ function do_calendar_startup(callback) {
   let startupService = Cc["@mozilla.org/calendar/startup-service;1"].getService(Ci.nsISupports)
     .wrappedJSObject;
 
   if (startupService.started) {
     callback();
   } else {
     do_test_pending();
     Services.obs.addObserver(obs, "calendar-startup-done");
-    if (_profileInitialized) {
+    if (this._profileInitialized) {
       Services.obs.notifyObservers(null, "profile-after-change", "xpcshell-do-get-profile");
     } else {
       do_get_profile(true);
     }
   }
 }
--- a/calendar/test/unit/test_extract.js
+++ b/calendar/test/unit/test_extract.js
@@ -177,17 +177,17 @@ function test_overrides() {
   // recognize a custom "tomorrow" and hour.minutes pattern
   let overrides = {
     "from.hour.minutes": { add: "#2:#1", remove: "#1:#2" },
     "from.tomorrow": { add: "worromot" },
   };
 
   Services.prefs.setStringPref("calendar.patterns.override", JSON.stringify(overrides));
 
-  collected = extractor.extract(title, content, date, undefined);
+  extractor.extract(title, content, date, undefined);
   guessed = extractor.guessStart(false);
   endGuess = extractor.guessEnd(guessed, true);
 
   equal(guessed.year, 2012);
   equal(guessed.month, 10);
   equal(guessed.day, 2);
   equal(guessed.hour, 11);
   equal(guessed.minute, 10);
--- a/calendar/test/unit/test_freebusy_service.js
+++ b/calendar/test/unit/test_freebusy_service.js
@@ -16,17 +16,17 @@ function really_run_test() {
 
 function test_found() {
   _clearProviders();
 
   equal(_countProviders(), 0);
 
   let provider1 = {
     id: 1,
-    getFreeBusyIntervals: function() {
+    getFreeBusyIntervals: function(aCalId, aStart, aEnd, aTypes, aListener) {
       aListener.onResult(null, []);
     },
   };
 
   let provider2 = {
     id: 2,
     called: false,
     getFreeBusyIntervals: function(aCalId, aStart, aEnd, aTypes, aListener) {
--- a/calendar/test/unit/test_itip_utils.js
+++ b/calendar/test/unit/test_itip_utils.js
@@ -198,17 +198,17 @@ function test_getSequence() {
     },
     {
       input: [{ attendee: { receivedSeq: "1" } }],
       expected: 1,
     },
   ];
   for (let i = 1; i <= data.length; i++) {
     let test = data[i - 1];
-    testItems = getSeqStampTestItems(test);
+    let testItems = getSeqStampTestItems(test);
     equal(cal.itip.getSequence(testItems[0], testItems[1]), test.expected, "(test #" + i + ")");
   }
 }
 
 function test_getStamp() {
   // assigning an empty string results in not having the property in the ics here. However, there
   // must be always an dtStamp for item - if it's missing it will be set by the test code to make
   // sure we get a valid ics
@@ -294,17 +294,17 @@ function test_compareSequence() {
     {
       // item.seq < attendee.seq
       input: [{ item: { sequence: "2" } }, { attendee: { receivedSeq: "3" } }],
       expected: -1,
     },
   ];
   for (let i = 1; i <= data.length; i++) {
     let test = data[i - 1];
-    testItems = getSeqStampTestItems(test);
+    let testItems = getSeqStampTestItems(test);
     equal(cal.itip.compareSequence(testItems[0], testItems[1]), test.expected, "(test #" + i + ")");
   }
 }
 
 function test_compareStamp() {
   // it is sufficient to test here with dtstamp for items - full test coverage for
   // x-moz-received-stamp is already provided by test_compareStamp
   let data = [
@@ -369,17 +369,17 @@ function test_compareStamp() {
         { item: { dtStamp: "20150910T181048Z" } },
         { attendee: { receivedStamp: "20150911T181048Z" } },
       ],
       expected: -1,
     },
   ];
   for (let i = 1; i <= data.length; i++) {
     let test = data[i - 1];
-    testItems = getSeqStampTestItems(test);
+    let testItems = getSeqStampTestItems(test);
     equal(cal.itip.compareStamp(testItems[0], testItems[1]), test.expected, "(test #" + i + ")");
   }
 }
 
 function test_compare() {
   // it is sufficient to test here with items only - full test coverage for attendees or
   // item/attendee is already provided by test_compareSequence and test_compareStamp
   let data = [
@@ -453,17 +453,17 @@ function test_compare() {
         { item: { sequence: "2", dtStamp: "20150910T181048Z" } },
         { item: { sequence: "3", dtStamp: "20150911T181048Z" } },
       ],
       expected: -1,
     },
   ];
   for (let i = 1; i <= data.length; i++) {
     let test = data[i - 1];
-    testItems = getSeqStampTestItems(test);
+    let testItems = getSeqStampTestItems(test);
     equal(cal.itip.compare(testItems[0], testItems[1]), test.expected, "(test #" + i + ")");
   }
 }
 
 function test_getAttendeesBySender() {
   let data = [
     {
       input: {
--- a/calendar/test/unit/test_recur.js
+++ b/calendar/test/unit/test_recur.js
@@ -1100,17 +1100,17 @@ function test_failures() {
       0,
       {}
     ).length,
     0
   );
 }
 
 function test_immutable() {
-  item = createTodoFromIcalString(
+  let item = createTodoFromIcalString(
     "BEGIN:VCALENDAR\r\n" +
       "BEGIN:VTODO\r\n" +
       "RRULE:FREQ=DAILY\r\n" +
       "END:VTODO\r\n" +
       "END:VCALENDAR\r\n"
   );
   ok(item.recurrenceInfo.isMutable);
   let rinfo = item.recurrenceInfo.clone();
deleted file mode 100644
--- a/mail/components/cloudfile/test/browser/.eslintrc.js
+++ /dev/null
@@ -1,10 +0,0 @@
-"use strict";
-
-module.exports = {
-  extends: "plugin:mozilla/browser-test",
-
-  rules: {
-    "func-names": "off",
-    "mozilla/import-headjs-globals": "error",
-  },
-};
deleted file mode 100644
--- a/mail/components/enterprisepolicies/tests/browser/.eslintrc.js
+++ /dev/null
@@ -1,10 +0,0 @@
-"use strict";
-
-module.exports = {
-  extends: "plugin:mozilla/browser-test",
-
-  rules: {
-    "func-names": "off",
-    "mozilla/import-headjs-globals": "error",
-  },
-};
--- a/mail/components/extensions/test/browser/.eslintrc.js
+++ b/mail/components/extensions/test/browser/.eslintrc.js
@@ -1,14 +1,7 @@
 "use strict";
 
 module.exports = {
-  extends: "plugin:mozilla/browser-test",
-
   env: {
     webextensions: true,
   },
-
-  rules: {
-    "func-names": "off",
-    "mozilla/import-headjs-globals": "error",
-  },
 };
--- a/mail/components/extensions/test/xpcshell/.eslintrc.js
+++ b/mail/components/extensions/test/xpcshell/.eslintrc.js
@@ -1,16 +1,7 @@
 "use strict";
 
 module.exports = {
-  extends: "plugin:mozilla/xpcshell-test",
-
   env: {
-    // The tests in this folder are testing based on WebExtensions, so lets
-    // just define the webextensions environment here.
     webextensions: true,
   },
-
-  rules: {
-    "func-names": "off",
-    "mozilla/import-headjs-globals": "error",
-  },
 };
deleted file mode 100644
--- a/mailnews/db/gloda/test/unit/.eslintrc.js
+++ /dev/null
@@ -1,21 +0,0 @@
-"use strict";
-
-module.exports = {
-  extends: "plugin:mozilla/xpcshell-test",
-
-  rules: {
-    "func-names": "off",
-    "mozilla/import-headjs-globals": "error",
-    "no-unused-vars": [
-      "error",
-      {
-        args: "none",
-        vars: "all",
-      },
-    ],
-  },
-
-  globals: {
-    do_report_result: false,
-  },
-};
--- a/mailnews/db/gloda/test/unit/head_gloda.js
+++ b/mailnews/db/gloda/test/unit/head_gloda.js
@@ -1,9 +1,8 @@
-/* exported mailTestUtils */
 var { mailTestUtils } = ChromeUtils.import(
   "resource://testing-common/mailnews/mailTestUtils.js"
 );
 
 // Ensure the profile directory is set up
 do_get_profile();
 
 var gDEPTH = "../../../../../";
deleted file mode 100644
--- a/mailnews/mime/jsmime/test/.eslintrc.js
+++ /dev/null
@@ -1,17 +0,0 @@
-"use strict";
-
-module.exports = {
-  extends: "plugin:mozilla/xpcshell-test",
-
-  rules: {
-    "func-names": "off",
-    "mozilla/import-headjs-globals": "error",
-    "no-unused-vars": [
-      "error",
-      {
-        args: "none",
-        vars: "all",
-      },
-    ],
-  },
-};
rename from mailnews/mime/jsmime/test/data/base64-1
rename to mailnews/mime/jsmime/test/unit/data/base64-1
rename from mailnews/mime/jsmime/test/data/base64-2
rename to mailnews/mime/jsmime/test/unit/data/base64-2
rename from mailnews/mime/jsmime/test/data/basic1
rename to mailnews/mime/jsmime/test/unit/data/basic1
rename from mailnews/mime/jsmime/test/data/bug505221
rename to mailnews/mime/jsmime/test/unit/data/bug505221
rename from mailnews/mime/jsmime/test/data/bugmail11
rename to mailnews/mime/jsmime/test/unit/data/bugmail11
rename from mailnews/mime/jsmime/test/data/charsets
rename to mailnews/mime/jsmime/test/unit/data/charsets
rename from mailnews/mime/jsmime/test/data/message-encoded
rename to mailnews/mime/jsmime/test/unit/data/message-encoded
rename from mailnews/mime/jsmime/test/data/mime-torture
rename to mailnews/mime/jsmime/test/unit/data/mime-torture
rename from mailnews/mime/jsmime/test/data/multipart-base64-1
rename to mailnews/mime/jsmime/test/unit/data/multipart-base64-1
rename from mailnews/mime/jsmime/test/data/multipart-base64-2
rename to mailnews/mime/jsmime/test/unit/data/multipart-base64-2
rename from mailnews/mime/jsmime/test/data/multipart-base64-3
rename to mailnews/mime/jsmime/test/unit/data/multipart-base64-3
rename from mailnews/mime/jsmime/test/data/multipart-complex1
rename to mailnews/mime/jsmime/test/unit/data/multipart-complex1
rename from mailnews/mime/jsmime/test/data/multipart-complex2
rename to mailnews/mime/jsmime/test/unit/data/multipart-complex2
rename from mailnews/mime/jsmime/test/data/multipart1
rename to mailnews/mime/jsmime/test/unit/data/multipart1
rename from mailnews/mime/jsmime/test/data/multipart2
rename to mailnews/mime/jsmime/test/unit/data/multipart2
rename from mailnews/mime/jsmime/test/data/multipart3
rename to mailnews/mime/jsmime/test/unit/data/multipart3
rename from mailnews/mime/jsmime/test/data/multipart4
rename to mailnews/mime/jsmime/test/unit/data/multipart4
rename from mailnews/mime/jsmime/test/data/multipartmalt-detach
rename to mailnews/mime/jsmime/test/unit/data/multipartmalt-detach
rename from mailnews/mime/jsmime/test/data/shift-jis-image
rename to mailnews/mime/jsmime/test/unit/data/shift-jis-image
rename from mailnews/mime/jsmime/test/head_xpcshell_glue.js
rename to mailnews/mime/jsmime/test/unit/head_xpcshell_glue.js
--- a/mailnews/mime/jsmime/test/head_xpcshell_glue.js
+++ b/mailnews/mime/jsmime/test/unit/head_xpcshell_glue.js
@@ -75,17 +75,16 @@ function innerDefine(moduleName, dfn) {
       path = path.substring(2);
     }
     return require(path);
   }
   var result = dfn(resolvingRequire);
   requireCache.set(moduleName, result);
 }
 
-/* exported define */
 var define = innerDefine.bind(this, "xpcshell-test");
 
 // Mocha TDD UI Bindings
 // ---------------------
 
 /**
  * A block of tests, from the suite class.
  */
@@ -139,17 +138,16 @@ function runFunction(fn) {
       // Promise.resolve nicely handles both promises and not-promise values for
       // us.
       resolve(fn());
     }
   });
   return completed;
 }
 
-/* exported suite, test, setup, teardown, run_test */
 var currentSuite = new MochaSuite("");
 function suite(name, tests) {
   name = name.toString();
   if (/[\x80-]/.exec(name)) {
     name = "<unprintable name>";
   }
   let suiteParent = currentSuite;
   currentSuite = new MochaSuite(name);
rename from mailnews/mime/jsmime/test/mock_date.js
rename to mailnews/mime/jsmime/test/unit/mock_date.js
rename from mailnews/mime/jsmime/test/test_custom_headers.js
rename to mailnews/mime/jsmime/test/unit/test_custom_headers.js
rename from mailnews/mime/jsmime/test/test_header.js
rename to mailnews/mime/jsmime/test/unit/test_header.js
rename from mailnews/mime/jsmime/test/test_header_emitter.js
rename to mailnews/mime/jsmime/test/unit/test_header_emitter.js
rename from mailnews/mime/jsmime/test/test_mime_tree.js
rename to mailnews/mime/jsmime/test/unit/test_mime_tree.js
rename from mailnews/mime/jsmime/test/test_structured_header_emitters.js
rename to mailnews/mime/jsmime/test/unit/test_structured_header_emitters.js
rename from mailnews/mime/jsmime/test/test_structured_headers.js
rename to mailnews/mime/jsmime/test/unit/test_structured_headers.js
rename from mailnews/mime/jsmime/test/xpcshell.ini
rename to mailnews/mime/jsmime/test/unit/xpcshell.ini
--- a/mailnews/mime/moz.build
+++ b/mailnews/mime/moz.build
@@ -12,12 +12,12 @@ DIRS += [
 
 TEST_DIRS += ['test']
 
 EXTRA_JS_MODULES.jsmime += [
     'jsmime/jsmime.js',
 ]
 
 TESTING_JS_MODULES.jsmime += [
-    'jsmime/test/mock_date.js',
+    'jsmime/test/unit/mock_date.js',
 ]
 
-XPCSHELL_TESTS_MANIFESTS += ['jsmime/test/xpcshell.ini']
+XPCSHELL_TESTS_MANIFESTS += ['jsmime/test/unit/xpcshell.ini']