From 5e22a6252261a80956277d00c73f5ed7a2f015b1 Mon Sep 17 00:00:00 2001 From: pipopotamasu Date: Wed, 21 Feb 2024 10:07:38 +0900 Subject: [PATCH] fix variable declaration by function (#46) --- rules/no-implicit-any/variable-declarator/index.spec.ts | 6 ++++++ rules/no-implicit-any/variable-declarator/index.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/rules/no-implicit-any/variable-declarator/index.spec.ts b/rules/no-implicit-any/variable-declarator/index.spec.ts index 6369ed0..1220e3e 100644 --- a/rules/no-implicit-any/variable-declarator/index.spec.ts +++ b/rules/no-implicit-any/variable-declarator/index.spec.ts @@ -24,6 +24,12 @@ ruleTester.run('variable-declarator', rule, { const { bar } = foo(); `, }, + { + code: ` + const foo = (): any => 'test'; + const val = foo(); + `, + }, { code: ` const foo = () => ([1, 2]); diff --git a/rules/no-implicit-any/variable-declarator/index.ts b/rules/no-implicit-any/variable-declarator/index.ts index 0f94d5d..fa74e94 100644 --- a/rules/no-implicit-any/variable-declarator/index.ts +++ b/rules/no-implicit-any/variable-declarator/index.ts @@ -11,6 +11,7 @@ export const lintVariableDeclarator = ( node.id.typeAnnotation || node.id.type === AST_NODE_TYPES.ObjectPattern || node.id.type === AST_NODE_TYPES.ArrayPattern || + node.init?.type === AST_NODE_TYPES.CallExpression || node.parent.type !== AST_NODE_TYPES.VariableDeclaration || node.parent.parent.type === AST_NODE_TYPES.ForOfStatement )