const utils_1 = require("@typescript-eslint/utils"); const getFunction_1 = require("../utils/getFunction"); const load_1 = require("../utils/load"); module.exports = { name: "no-empty-load", meta: { type: "problem", messages: { emptyLoad: "Calling load without any argument slows down your add-in.", }, docs: { description: "Calling load without any argument causes unneeded data to load and slows down your add-in.", category: "Best Practices", recommended: false, url: "https://docs.microsoft.com/office/dev/add-ins/develop/application-specific-api-model#calling-load-without-parameters-not-recommended", }, schema: [], }, create: function (context) { function isEmptyLoad(node) { if ((0, load_1.isLoadFunction)(node)) { const propertyNames = (0, load_1.parseLoadArguments)(node); if (propertyNames.length === 0) { return true; } let foundEmptyProperty = false; propertyNames.forEach((property) => { if (!property) { foundEmptyProperty = true; } }); return foundEmptyProperty; } return false; } function findEmptyLoad(scope) { scope.variables.forEach((variable) => { let getFound = false; variable.references.forEach((reference) => { var _a; const node = reference.identifier; if (reference.isWrite()) { getFound = false; // In case of reassignment if (reference.writeExpr && (0, getFunction_1.isGetFunction)(reference.writeExpr)) { getFound = true; return; } } if (!getFound) { // If reference was not related to a previous get return; } if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.TSESTree.AST_NODE_TYPES.MemberExpression && isEmptyLoad(node.parent)) { context.report({ node: node.parent, messageId: "emptyLoad", }); } }); }); scope.childScopes.forEach(findEmptyLoad); } return { Program() { findEmptyLoad(context.getScope()); }, }; }, }; //# sourceMappingURL=no-empty-load.js.map