Files
2025-03-07 19:22:02 +01:00

76 lines
3.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@typescript-eslint/utils");
const getFunction_1 = require("../utils/getFunction");
const load_1 = require("../utils/load");
exports.default = utils_1.ESLintUtils.RuleCreator(() => "https://docs.microsoft.com/office/dev/add-ins/develop/application-specific-api-model#calling-load-without-parameters-not-recommended")({
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.",
},
schema: [],
},
create: function (context) {
var _a;
const sourceCode = (_a = context.sourceCode) !== null && _a !== void 0 ? _a : context.getSourceCode();
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(node) {
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();
findEmptyLoad(scope);
},
};
},
defaultOptions: [],
});
//# sourceMappingURL=no-empty-load.js.map