Bug 1388215: Part 2 - Add eslint plugin support for defineLazy*Getters() methods. r=florian
authorKris Maglione <maglione.k@gmail.com>
Tue, 08 Aug 2017 14:11:16 -0700
changeset 373876 5294842bfd83
parent 373875 6e923e11fbb5
child 373877 7b9ab0caee26
push id32311
push userkwierso@gmail.com
push dateFri, 11 Aug 2017 01:14:57 +0000
treeherdermozilla-central@253a8560dc34 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1388215
milestone57.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 1388215: Part 2 - Add eslint plugin support for defineLazy*Getters() methods. r=florian MozReview-Commit-ID: AMX0VbPncmI
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
@@ -29,16 +29,21 @@ const callExpressionDefinitions = [
   /^XPCOMUtils\.defineConstant\(this, "(\w+)"/,
   /^DevToolsUtils\.defineLazyModuleGetter\(this, "(\w+)"/,
   /^DevToolsUtils\.defineLazyGetter\(this, "(\w+)"/,
   /^Object\.defineProperty\(this, "(\w+)"/,
   /^Reflect\.defineProperty\(this, "(\w+)"/,
   /^this\.__defineGetter__\("(\w+)"/
 ];
 
+const callExpressionMultiDefinitions = [
+  "XPCOMUtils.defineLazyModuleGetters(this,",
+  "XPCOMUtils.defineLazyServiceGetters(this,"
+];
+
 const imports = [
   /^(?:Cu|Components\.utils)\.import\(".*\/((.*?)\.jsm?)"(?:, this)?\)/
 ];
 
 const workerImportFilenameMatch = /(.*\/)*(.*?\.jsm?)/;
 
 module.exports = {
   get modulesGlobalData() {
@@ -276,16 +281,24 @@ module.exports = {
 
     for (let reg of callExpressionDefinitions) {
       let match = source.match(reg);
       if (match) {
         return [{ name: match[1], writable: 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 }))
+                 .filter(g => g.name);
+    }
+
     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 }));
     }