From 2ada5aff1ef37bc260d7a0eaafe9ff04f8a08fe4 Mon Sep 17 00:00:00 2001 From: Gaon Kim Date: Mon, 7 Sep 2020 03:30:59 +0900 Subject: [PATCH] fix(eslint-plugin): [typedef] false positive for rest parameter with array destructuring (#2441) --- packages/eslint-plugin/src/rules/typedef.ts | 6 ++++++ .../eslint-plugin/tests/rules/typedef.test.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/eslint-plugin/src/rules/typedef.ts b/packages/eslint-plugin/src/rules/typedef.ts index 1d66cff42902..766401040224 100644 --- a/packages/eslint-plugin/src/rules/typedef.ts +++ b/packages/eslint-plugin/src/rules/typedef.ts @@ -141,6 +141,12 @@ export default util.createRule<[Options], MessageIds>({ return { ArrayPattern(node): void { + if ( + node.parent?.type === AST_NODE_TYPES.RestElement && + node.parent.typeAnnotation + ) { + return; + } if ( options[OptionKeys.ArrayDestructuring] && !node.typeAnnotation && diff --git a/packages/eslint-plugin/tests/rules/typedef.test.ts b/packages/eslint-plugin/tests/rules/typedef.test.ts index f3c240077168..09a4764a0ba3 100644 --- a/packages/eslint-plugin/tests/rules/typedef.test.ts +++ b/packages/eslint-plugin/tests/rules/typedef.test.ts @@ -14,6 +14,22 @@ const ruleTester = new RuleTester({ ruleTester.run('typedef', rule, { valid: [ // Array destructuring + { + code: 'function foo(...[a]: string[]) {}', + options: [ + { + arrayDestructuring: true, + }, + ], + }, + { + code: 'const foo = (...[a]: string[]) => {};', + options: [ + { + arrayDestructuring: true, + }, + ], + }, { code: 'const [a]: [number] = [1];', options: [