Skip to content

Commit 264100d

Browse files
committed
Fix coderabbit errors
1 parent 45c2e94 commit 264100d

File tree

23 files changed

+215
-367
lines changed

23 files changed

+215
-367
lines changed

eslint-rules/require-security-check.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ import { ESLintUtils } from '@typescript-eslint/utils';
1818
// Walk the AST to find a node that matches the callback, up to maxDepth levels deep
1919
// This is a depth-first search and could be improved
2020
function walkFind(
21-
node: TSESTree.Node,
21+
node: TSESTree.Node | undefined | null,
2222
callback: (node: TSESTree.Node) => boolean,
2323
maxDepth = 10
2424
): TSESTree.Node | null {
2525
if (maxDepth <= 0) return null;
26+
if (node && typeof node !== 'object') return null;
2627
if (callback(node)) return node;
2728
for (const key in node) {
2829
if (key === 'parent') continue;
@@ -37,6 +38,7 @@ function walkFind(
3738
if (result) return result;
3839
}
3940
}
41+
return null;
4042
}
4143

4244
function blockStatementIncludesSecurityCall(block: TSESTree.BlockStatement): boolean {
@@ -208,14 +210,21 @@ export default ESLintUtils.RuleCreator(() => '')({
208210
} else {
209211
// This is a single function (load or endpoint), so find its body
210212
// There should be a block statement (function body) within a couple levels
211-
blockStatements.push(
212-
walkFind(
213-
(functionExport as TSESTree.VariableDeclaratorMaybeInit).init ||
214-
(functionExport as TSESTree.FunctionDeclaration),
215-
(n) => n.type === 'BlockStatement',
216-
4
217-
) as TSESTree.BlockStatement
218-
);
213+
const blockStatement = walkFind(
214+
(functionExport as TSESTree.VariableDeclaratorMaybeInit).init ||
215+
(functionExport as TSESTree.FunctionDeclaration),
216+
(n) => n.type === 'BlockStatement',
217+
4
218+
) as TSESTree.BlockStatement;
219+
if (blockStatement) blockStatements.push(blockStatement);
220+
else {
221+
context.report({
222+
node: node.declaration,
223+
data: { type: functionExport.type },
224+
messageId: 'unexpectedFunction'
225+
});
226+
return;
227+
}
219228
}
220229
blockStatements.forEach((bs) => {
221230
if (!blockStatementIncludesSecurityCall(bs)) {

0 commit comments

Comments
 (0)