Bug 1464548: Part 2 - Add ESLint support for defineLazyGlobalGetters. r=standard8
authorKris Maglione <maglione.k@gmail.com>
Fri, 25 May 2018 22:27:00 -0700
changeset 476128 a6e7bfa38103efc76635dfd8d4ecd6bf51a6c590
parent 476127 4a8cd93316d6785a593b204bc204d6004449d76a
child 476129 22daf991f7b705c6849c5597f9794f1ac8f86a8e
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs1464548
milestone62.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 1464548: Part 2 - Add ESLint support for defineLazyGlobalGetters. r=standard8 MozReview-Commit-ID: 38hk1MquFrg
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -32,16 +32,17 @@ const callExpressionDefinitions = [
   /^DevToolsUtils\.defineLazyModuleGetter\(this, "(\w+)"/,
   /^DevToolsUtils\.defineLazyGetter\(this, "(\w+)"/,
   /^Object\.defineProperty\(this, "(\w+)"/,
   /^Reflect\.defineProperty\(this, "(\w+)"/,
   /^this\.__defineGetter__\("(\w+)"/
 ];
 
 const callExpressionMultiDefinitions = [
+  "XPCOMUtils.defineLazyGlobalGetters(this,",
   "XPCOMUtils.defineLazyModuleGetters(this,",
   "XPCOMUtils.defineLazyServiceGetters(this,"
 ];
 
 const imports = [
   /^(?:Cu|Components\.utils|ChromeUtils)\.import\(".*\/((.*?)\.jsm?)"(?:, this)?\)/
 ];
 
@@ -303,21 +304,28 @@ module.exports = {
     for (let reg of callExpressionDefinitions) {
       let match = source.match(reg);
       if (match) {
         return [{ name: match[1], writable: true, explicit: true }];
       }
     }
 
     if (callExpressionMultiDefinitions.some(expr => source.startsWith(expr)) &&
-        node.expression.arguments[1] &&
-        node.expression.arguments[1].type === "ObjectExpression") {
-      return node.expression.arguments[1].properties
-                 .map(p => ({ name: p.type === "Property" && p.key.name, writable: true, explicit: true }))
-                 .filter(g => g.name);
+        node.expression.arguments[1]) {
+      let arg = node.expression.arguments[1];
+      if (arg.type === "ObjectExpression") {
+        return arg.properties
+                  .map(p => ({ name: p.type === "Property" && p.key.name, writable: true, explicit: true }))
+                  .filter(g => g.name);
+      }
+      if (arg.type === "ArrayExpression") {
+        return arg.elements
+                  .map(p => ({ name: p.type === "Literal" && p.value, writable: true, explicit: true }))
+                  .filter(g => typeof g.name == "string");
+      }
     }
 
     if (node.expression.callee.type == "MemberExpression" &&
         node.expression.callee.property.type == "Identifier" &&
         node.expression.callee.property.name == "defineLazyScriptGetter") {
       // The case where we have a single symbol as a string has already been
       // handled by the regexp, so we have an array of symbols here.
       return node.expression.arguments[1].elements.map(n => ({ name: n.value, writable: true, explicit: true }));