diff --git a/rules/no-implicit-any/function-args/index.spec.ts b/rules/no-implicit-any/function-args/index.spec.ts index 3659110..3212a41 100644 --- a/rules/no-implicit-any/function-args/index.spec.ts +++ b/rules/no-implicit-any/function-args/index.spec.ts @@ -13,6 +13,9 @@ ruleTester.run('function-args', rule, { { code: 'function foo (arg1: any = null, arg2: any = undefined, arg3: any[] = []) {}', }, + { + code: 'function foo ({ a: { b: { c } } }: any) {}', + }, { code: 'const arrayObjFunc = [{ key: function (arg1: any, arg2: any) {} }];', }, @@ -47,6 +50,9 @@ ruleTester.run('function-args', rule, { { code: 'const foo = (arg: any = {}) => {};', }, + { + code: 'const foo = ({ a: { b: { c } } }: any) => {}', + }, { code: 'const arrayObjArrowFunc = [{ key: (arg1: any, arg2: any ) => {} }];', }, @@ -203,6 +209,11 @@ ruleTester.run('function-args', rule, { { messageId: 'missingAnyType' }, ], }, + { + code: 'function foo ({ a: { b: { c } } }) {}', + output: 'function foo ({ a: { b: { c } } }: any) {}', + errors: [{ messageId: 'missingAnyType' }], + }, { code: 'const arrayObjFunc = [{ key: function (arg1, arg2) {} }];', output: 'const arrayObjFunc = [{ key: function (arg1: any, arg2: any) {} }];', @@ -211,7 +222,7 @@ ruleTester.run('function-args', rule, { { code: 'function foo ({ arg1, arg2 }) {}', output: 'function foo ({ arg1, arg2 }: any) {}', - errors: [{ messageId: 'missingAnyType' }, { messageId: 'missingAnyType' }], + errors: [{ messageId: 'missingAnyType' }], }, { code: 'function foo ({ arg1, ...rest }) {}', @@ -243,6 +254,11 @@ ruleTester.run('function-args', rule, { { messageId: 'missingAnyType' }, ], }, + { + code: 'const foo = ({ a: { b: { c } } }) => {}', + output: 'const foo = ({ a: { b: { c } } }: any) => {}', + errors: [{ messageId: 'missingAnyType' }], + }, { code: 'const foo = arg => {}', output: 'const foo = (arg: any) => {}', @@ -261,7 +277,7 @@ ruleTester.run('function-args', rule, { { code: 'const foo = ({ arg1, arg2 }) => {}', output: 'const foo = ({ arg1, arg2 }: any) => {}', - errors: [{ messageId: 'missingAnyType' }, { messageId: 'missingAnyType' }], + errors: [{ messageId: 'missingAnyType' }], }, { code: 'const foo = ({ arg1, ...rest }) => {}', diff --git a/rules/no-implicit-any/function-args/index.ts b/rules/no-implicit-any/function-args/index.ts index f4309ab..aceb51b 100644 --- a/rules/no-implicit-any/function-args/index.ts +++ b/rules/no-implicit-any/function-args/index.ts @@ -70,22 +70,16 @@ function lintArg( }, }); } else if (type.flags === ts.TypeFlags.Object) { - if (arg.type === AST_NODE_TYPES.ObjectPattern) { - arg.properties.forEach((property) => { - if (property.type === AST_NODE_TYPES.Property) { - if (!property.key['typeAnnotation']) { - const type = parserServices.getTypeAtLocation(property); - if (type.flags === ts.TypeFlags.Any) { - context.report({ - node: arg, - messageId: 'missingAnyType', - fix(fixer) { - return fixer.insertTextAfter(arg, ': any'); - }, - }); - } - } - } + if ( + arg.type === AST_NODE_TYPES.ObjectPattern && + !(arg.properties.length === 1 && arg.properties[0].type === AST_NODE_TYPES.RestElement) + ) { + context.report({ + node: arg, + messageId: 'missingAnyType', + fix(fixer) { + return fixer.insertTextAfter(arg, ': any'); + }, }); } else if ( arg.type === AST_NODE_TYPES.ArrayPattern ||