@stackr/eslint-plugin
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -105,38 +105,48 @@ "use strict"; | ||
node.declarations.forEach((declarator) => { | ||
var _a, _b, _c, _d, _e, _f; | ||
const isRelevantFunction = FUNCTION_IDENTIFIERS.includes((_d = (_c = (_b = (_a = declarator.id) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.typeAnnotation) === null || _c === void 0 ? void 0 : _c.typeName) === null || _d === void 0 ? void 0 : _d.name); | ||
if (isRelevantFunction) { | ||
const handlerFnNode = declarator.init.properties.find((f) => f.key.name === HANDLER_KEY); | ||
if ((_f = (_e = handlerFnNode === null || handlerFnNode === void 0 ? void 0 : handlerFnNode.value) === null || _e === void 0 ? void 0 : _e.body) === null || _f === void 0 ? void 0 : _f.body) { | ||
const nodes = handlerFnNode.value.body.body; | ||
nodes.forEach((node) => { | ||
switch (node.type) { | ||
case utils_1.AST_NODE_TYPES.VariableDeclaration: | ||
node.declarations.forEach((declaration) => { | ||
if (declaration.init) { | ||
handleAllCases(declaration.init, context); | ||
} | ||
}); | ||
break; | ||
case utils_1.AST_NODE_TYPES.ExpressionStatement: | ||
const expression = node.expression; | ||
if (expression) { | ||
handleAllCases(expression, context); | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
// for syntax before SDK v0.6.0 | ||
const isRelevantTypeNotation = FUNCTION_IDENTIFIERS.includes((_d = (_c = (_b = (_a = declarator.id) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.typeAnnotation) === null || _c === void 0 ? void 0 : _c.typeName) === null || _d === void 0 ? void 0 : _d.name); | ||
// for syntax after SDK v0.6.0 | ||
const isRelevantCallExpression = ((_e = declarator === null || declarator === void 0 ? void 0 : declarator.id) === null || _e === void 0 ? void 0 : _e.type) === utils_1.AST_NODE_TYPES.Identifier && | ||
((_f = declarator === null || declarator === void 0 ? void 0 : declarator.init) === null || _f === void 0 ? void 0 : _f.type) === utils_1.AST_NODE_TYPES.CallExpression && | ||
((_h = (_g = declarator === null || declarator === void 0 ? void 0 : declarator.init) === null || _g === void 0 ? void 0 : _g.callee) === null || _h === void 0 ? void 0 : _h.type) === utils_1.AST_NODE_TYPES.MemberExpression && | ||
FUNCTION_IDENTIFIERS.includes((_l = (_k = (_j = declarator === null || declarator === void 0 ? void 0 : declarator.init) === null || _j === void 0 ? void 0 : _j.callee) === null || _k === void 0 ? void 0 : _k.property) === null || _l === void 0 ? void 0 : _l.name); | ||
let handlerFnNode; | ||
if (isRelevantTypeNotation) { | ||
handlerFnNode = declarator.init.properties.find((f) => f.key.name === HANDLER_KEY); | ||
} | ||
else if (isRelevantCallExpression) { | ||
handlerFnNode = declarator.init.arguments[0].properties.find((f) => f.key.name === HANDLER_KEY); | ||
} | ||
if ((_o = (_m = handlerFnNode === null || handlerFnNode === void 0 ? void 0 : handlerFnNode.value) === null || _m === void 0 ? void 0 : _m.body) === null || _o === void 0 ? void 0 : _o.body) { | ||
const nodes = handlerFnNode.value.body.body; | ||
nodes.forEach((node) => { | ||
switch (node.type) { | ||
case utils_1.AST_NODE_TYPES.VariableDeclaration: | ||
node.declarations.forEach((declaration) => { | ||
if (declaration.init) { | ||
handleAllCases(declaration.init, context); | ||
} | ||
break; | ||
case utils_1.AST_NODE_TYPES.ReturnStatement: | ||
const argument = node.argument; | ||
if (argument) { | ||
handleAllCases(argument, context); | ||
} | ||
break; | ||
case utils_1.AST_NODE_TYPES.IfStatement: | ||
const test = node.test; | ||
if (test) { | ||
handleAllCases(test, context); | ||
} | ||
break; | ||
} | ||
}); | ||
} | ||
}); | ||
break; | ||
case utils_1.AST_NODE_TYPES.ExpressionStatement: | ||
const expression = node.expression; | ||
if (expression) { | ||
handleAllCases(expression, context); | ||
} | ||
break; | ||
case utils_1.AST_NODE_TYPES.ReturnStatement: | ||
const argument = node.argument; | ||
if (argument) { | ||
handleAllCases(argument, context); | ||
} | ||
break; | ||
case utils_1.AST_NODE_TYPES.IfStatement: | ||
const test = node.test; | ||
if (test) { | ||
handleAllCases(test, context); | ||
} | ||
break; | ||
} | ||
}); | ||
} | ||
@@ -143,0 +153,0 @@ }); |
{ | ||
"name": "@stackr/eslint-plugin", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Guardrails to prevent bad practices in Stackr's Micro-rollup codebase.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
11368
203