From 501faebb6e2086f9fdbc7114fa9e40dac9379576 Mon Sep 17 00:00:00 2001 From: pipopotamasu Date: Sat, 24 Feb 2024 06:34:42 +0900 Subject: [PATCH] add let and var declaration patterns (#50) --- .../variable-declarator/index.spec.ts | 62 +++++++++++++++---- .../variable-declarator/index.ts | 3 +- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/rules/no-implicit-any/variable-declarator/index.spec.ts b/rules/no-implicit-any/variable-declarator/index.spec.ts index 88b57aa..f408e75 100644 --- a/rules/no-implicit-any/variable-declarator/index.spec.ts +++ b/rules/no-implicit-any/variable-declarator/index.spec.ts @@ -6,18 +6,6 @@ ruleTester.run('variable-declarator', rule, { { code: 'const foo: any;', }, - { - code: 'let foo;', - }, - { - code: 'var foo;', - }, - { - code: 'let foo = null', - }, - { - code: 'var foo = null', - }, { code: ` const foo: any = {}; @@ -87,5 +75,55 @@ ruleTester.run('variable-declarator', rule, { output: 'const foo: any = void 0', errors: [{ messageId: 'missingAnyType' }], }, + { + code: 'let foo;', + output: 'let foo: any;', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'let foo, bar;', + output: 'let foo: any, bar: any;', + errors: [{ messageId: 'missingAnyType' }, { messageId: 'missingAnyType' }], + }, + { + code: 'let foo = null', + output: 'let foo: any = null', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'let foo = undefined', + output: 'let foo: any = undefined', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'let foo = void 0', + output: 'let foo: any = void 0', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'var foo;', + output: 'var foo: any;', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'var foo, bar;', + output: 'var foo: any, bar: any;', + errors: [{ messageId: 'missingAnyType' }, { messageId: 'missingAnyType' }], + }, + { + code: 'var foo = null', + output: 'var foo: any = null', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'var foo = undefined', + output: 'var foo: any = undefined', + errors: [{ messageId: 'missingAnyType' }], + }, + { + code: 'var foo = void 0', + output: 'var foo: any = void 0', + errors: [{ messageId: 'missingAnyType' }], + }, ], }); diff --git a/rules/no-implicit-any/variable-declarator/index.ts b/rules/no-implicit-any/variable-declarator/index.ts index aa6f44b..c14fc8a 100644 --- a/rules/no-implicit-any/variable-declarator/index.ts +++ b/rules/no-implicit-any/variable-declarator/index.ts @@ -9,8 +9,7 @@ export const lintVariableDeclarator = ( if ( node.id.typeAnnotation || node.parent.parent.type === AST_NODE_TYPES.ForOfStatement || - node.parent.parent.type === AST_NODE_TYPES.ForInStatement || - (node.parent.type === AST_NODE_TYPES.VariableDeclaration && node.parent.kind !== 'const') + node.parent.parent.type === AST_NODE_TYPES.ForInStatement ) return;