Skip to content

Commit 9a22040

Browse files
committed
start of work on next case
1 parent 7a10045 commit 9a22040

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

plugins/eslint-plugin-aws-toolkits/lib/rules/no-async-in-foreach.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ function getClassDeclarationNode<T extends string, T2 extends readonly unknown[]
6161
?.node as TSESTree.ClassDeclaration) ?? undefined
6262
return maybeDefNode
6363
}
64+
if (node.type === AST_NODE_TYPES.Identifier) {
65+
const scope = context.sourceCode.getScope(node)
66+
const maybeDefNode = scope.variables.find((v) => v.name === node.name)?.defs.find((d) => !!d)?.node ?? undefined
67+
console.log('got maybeDefNode %O', maybeDefNode)
68+
return undefined
69+
}
6470
}
6571

6672
function isAsyncClassMethod(defObjNode: TSESTree.ClassDeclaration, functionName: string): boolean {

plugins/eslint-plugin-aws-toolkits/test/rules/no-async-in-foreach.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ getRuleTester().run('no-async-in-foreach', rules['no-async-in-foreach'], {
3030
code: 'class c { \n public async f() {} \n } \n const c2 = new c() \n list.forEach(c2.f)',
3131
errors: [errMsg],
3232
},
33-
{ code: 'function f() { \n return async function () {}} \n [].forEach(f())', errors: [errMsg] },
34-
{
35-
code: 'function f() { \n return new (class c { \n public async f2() {} \n })().f2 \n } \n list.forEach(f())',
36-
errors: [errMsg],
37-
},
38-
{
39-
code: 'function f() { \n return function f2() { \n return function f3() { \n return function f4() { \n return function f5() { \n return async function f6() { \n \n } \n } \n } \n } \n } \n } \n list.forEach(f()()()()())',
40-
errors: [errMsg],
41-
},
33+
// { code: 'function f() { \n return async function () {}} \n [].forEach(f())', errors: [errMsg] },
34+
// {
35+
// code: 'function f() { \n return new (class c { \n public async f2() {} \n })().f2 \n } \n list.forEach(f())',
36+
// errors: [errMsg],
37+
// },
38+
// {
39+
// code: 'function f() { \n return function f2() { \n return function f3() { \n return function f4() { \n return function f5() { \n return async function f6() { \n \n } \n } \n } \n } \n } \n } \n list.forEach(f()()()()())',
40+
// errors: [errMsg],
41+
// },
4242
],
4343
})

0 commit comments

Comments
 (0)