Skip to content

Commit

Permalink
fix(eslint-plugin): [typedef] false positive for rest parameter with …
Browse files Browse the repository at this point in the history
…array destructuring (#2441)
  • Loading branch information
gaonK committed Sep 6, 2020
1 parent cdb9807 commit 2ada5af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/eslint-plugin/src/rules/typedef.ts
Expand Up @@ -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 &&
Expand Down
16 changes: 16 additions & 0 deletions packages/eslint-plugin/tests/rules/typedef.test.ts
Expand Up @@ -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: [
Expand Down

0 comments on commit 2ada5af

Please sign in to comment.