Skip to content

Commit 5bd0fb7

Browse files
brettz9gajus
authored andcommitted
feat: support <ArrayPattern> (Fixes #94) (#117)
- Docs (README): Update `<ObjectPattern>` link
1 parent 7a34bb1 commit 5bd0fb7

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

.README/rules/check-param-names.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ function quux ({
2525
}
2626
```
2727

28-
`{a, b}` is an [`ObjectPattern`](https://github.com/estree/estree/blob/master/es6.md#objectpattern) AST type and does not have a name. Therefore, the associated parameter in JSDoc block can have any name.
28+
`{a, b}` is an [`ObjectPattern`](https://github.com/estree/estree/blob/master/es2015.md#objectpattern) AST type and does not have a name. Therefore, the associated parameter in JSDoc block can have any name.
29+
30+
Likewise for the pattern `[a, b]` which is an [`ArrayPattern`](https://github.com/estree/estree/blob/master/es2015.md#arraypattern).

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ function quux ({a, b}) {
313313
*/
314314
function quux ({a, b} = {}) {
315315

316+
}
317+
318+
/**
319+
* @param foo
320+
*/
321+
function quux ([a, b] = []) {
322+
316323
}
317324
```
318325

@@ -334,7 +341,9 @@ function quux ({
334341
}
335342
```
336343

337-
`{a, b}` is an [`ObjectPattern`](https://github.com/estree/estree/blob/master/es6.md#objectpattern) AST type and does not have a name. Therefore, the associated parameter in JSDoc block can have any name.
344+
`{a, b}` is an [`ObjectPattern`](https://github.com/estree/estree/blob/master/es2015.md#objectpattern) AST type and does not have a name. Therefore, the associated parameter in JSDoc block can have any name.
345+
346+
Likewise for the pattern `[a, b]` which is an [`ArrayPattern`](https://github.com/estree/estree/blob/master/es2015.md#arraypattern).
338347

339348
<a name="eslint-plugin-jsdoc-rules-check-tag-names"></a>
340349
### <code>check-tag-names</code>

src/jsdocUtils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const getFunctionParameterNames = (functionNode : Object) : Array<string> => {
1515
return '<ObjectPattern>';
1616
}
1717

18+
if (param.type === 'ArrayPattern' || _.get(param, 'left.type') === 'ArrayPattern') {
19+
return '<ArrayPattern>';
20+
}
21+
1822
if (param.type === 'RestElement') {
1923
return param.argument.name;
2024
}

src/rules/checkParamNames.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const validateParameterNames = (targetTagName : string, functionParameterNames :
1111
return true;
1212
}
1313

14-
if (functionParameterName === '<ObjectPattern>') {
14+
if (functionParameterName === '<ObjectPattern>' || functionParameterName === '<ArrayPattern>') {
1515
return false;
1616
}
1717

test/rules/assertions/checkParamNames.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ export default {
199199
*/
200200
function quux ({a, b} = {}) {
201201
202+
}
203+
`
204+
},
205+
{
206+
code: `
207+
/**
208+
* @param foo
209+
*/
210+
function quux ([a, b] = []) {
211+
202212
}
203213
`
204214
}

0 commit comments

Comments
 (0)