Skip to content

Commit

Permalink
add let and var declaration patterns (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
pipopotamasu authored Feb 23, 2024
1 parent 82b0f55 commit 501faeb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
62 changes: 50 additions & 12 deletions rules/no-implicit-any/variable-declarator/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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' }],
},
],
});
3 changes: 1 addition & 2 deletions rules/no-implicit-any/variable-declarator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 501faeb

Please sign in to comment.