Bug 1464548: Part 2 - Add ESLint support for defineLazyGlobalGetters. r=standard8

MozReview-Commit-ID: 38hk1MquFrg

--HG--
extra : rebase_source : 8b418883093e15ed2ae7d052d7f191fc07e93636
This commit is contained in:
Kris Maglione 2018-05-25 22:27:00 -07:00
parent a4973ad0d6
commit 4eacff920e

View File

@ -37,6 +37,7 @@ const callExpressionDefinitions = [
];
const callExpressionMultiDefinitions = [
"XPCOMUtils.defineLazyGlobalGetters(this,",
"XPCOMUtils.defineLazyModuleGetters(this,",
"XPCOMUtils.defineLazyServiceGetters(this,"
];
@ -308,12 +309,19 @@ module.exports = {
}
if (callExpressionMultiDefinitions.some(expr => source.startsWith(expr)) &&
node.expression.arguments[1] &&
node.expression.arguments[1].type === "ObjectExpression") {
return node.expression.arguments[1].properties
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" &&