Skip to content

Commit 2ada5af

Browse files
authored
fix(eslint-plugin): [typedef] false positive for rest parameter with array destructuring (#2441)
1 parent cdb9807 commit 2ada5af

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: packages/eslint-plugin/src/rules/typedef.ts

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ export default util.createRule<[Options], MessageIds>({
141141

142142
return {
143143
ArrayPattern(node): void {
144+
if (
145+
node.parent?.type === AST_NODE_TYPES.RestElement &&
146+
node.parent.typeAnnotation
147+
) {
148+
return;
149+
}
144150
if (
145151
options[OptionKeys.ArrayDestructuring] &&
146152
!node.typeAnnotation &&

Diff for: packages/eslint-plugin/tests/rules/typedef.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ const ruleTester = new RuleTester({
1414
ruleTester.run('typedef', rule, {
1515
valid: [
1616
// Array destructuring
17+
{
18+
code: 'function foo(...[a]: string[]) {}',
19+
options: [
20+
{
21+
arrayDestructuring: true,
22+
},
23+
],
24+
},
25+
{
26+
code: 'const foo = (...[a]: string[]) => {};',
27+
options: [
28+
{
29+
arrayDestructuring: true,
30+
},
31+
],
32+
},
1733
{
1834
code: 'const [a]: [number] = [1];',
1935
options: [

0 commit comments

Comments
 (0)