@inngest/eslint-plugin
Version:
An ESLint plugin and config for [`inngest`](/packages/inngest/).
72 lines (71 loc) • 2.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.noVariableMutationInStep = void 0;
const utils_1 = require("@typescript-eslint/utils");
exports.noVariableMutationInStep = {
meta: {
type: "problem",
docs: {
description: "disallow mutating variables inside `step.run()`",
recommended: "recommended",
},
schema: [], // no options
messages: {
"no-variable-mutation-in-step": "Do not mutate variables inside `step.run()`, return the result instead",
},
},
defaultOptions: [],
create(context) {
let inStepRun = false;
const declaredVariables = new Set();
return {
VariableDeclaration(node) {
if (!inStepRun) {
node.declarations.forEach((declaration) => {
if (declaration.id.type === utils_1.AST_NODE_TYPES.Identifier) {
declaredVariables.add(declaration.id.name);
}
});
}
},
AssignmentExpression(node) {
if (inStepRun &&
node.left.type === utils_1.AST_NODE_TYPES.Identifier &&
declaredVariables.has(node.left.name)) {
context.report({
node,
messageId: "no-variable-mutation-in-step",
});
}
},
UpdateExpression(node) {
if (inStepRun &&
node.argument.type === utils_1.AST_NODE_TYPES.Identifier &&
declaredVariables.has(node.argument.name)) {
context.report({
node,
messageId: "no-variable-mutation-in-step",
});
}
},
CallExpression(node) {
if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression &&
node.callee.object.type === utils_1.AST_NODE_TYPES.Identifier &&
node.callee.object.name === "step" &&
node.callee.property.type === utils_1.AST_NODE_TYPES.Identifier &&
node.callee.property.name === "run") {
inStepRun = true;
}
},
"CallExpression:exit"(node) {
if (node.callee.type === utils_1.AST_NODE_TYPES.MemberExpression &&
node.callee.object.type === utils_1.AST_NODE_TYPES.Identifier &&
node.callee.object.name === "step" &&
node.callee.property.type === utils_1.AST_NODE_TYPES.Identifier &&
node.callee.property.name === "run") {
inStepRun = false;
}
},
};
},
};
;