Skip to content

Commit 2781cc8

Browse files
committed
- Fix: Filtering tags (as with lodash) to allow for missing array; add test
1 parent 336589d commit 2781cc8

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

src/iterateJsdoc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ const curryUtils = (
173173
};
174174

175175
utils.getTags = (tagName) => {
176-
if (!jsdoc.tags) {
177-
return [];
178-
}
179-
180-
return jsdoc.tags.filter((item) => {
176+
return utils.filterTags((item) => {
181177
return item.tag === tagName;
182178
});
183179
};
@@ -186,6 +182,10 @@ const curryUtils = (
186182
return forceRequireReturn;
187183
};
188184

185+
utils.filterTags = (filter) => {
186+
return (jsdoc.tags || []).filter(filter);
187+
};
188+
189189
utils.getClassNode = () => {
190190
const greatGrandParent = ancestors.slice(-3)[0];
191191
const greatGrandParentValue = greatGrandParent && sourceCode.getFirstToken(greatGrandParent).value;

src/rules/checkTypes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ const strictNativeTypes = [
1515
];
1616

1717
export default iterateJsdoc(({
18-
jsdoc,
1918
jsdocNode,
2019
sourceCode,
2120
report,
2221
utils
2322
}) => {
24-
const jsdocTags = jsdoc.tags.filter((tag) => {
23+
const jsdocTags = utils.filterTags((tag) => {
2524
return utils.isTagWithType(tag.tag);
2625
});
2726

src/rules/matchDescription.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const tagsWithDescriptions = ['param', 'arg', 'argument', 'returns', 'return'];
66
export default iterateJsdoc(({
77
jsdoc,
88
report,
9-
context
9+
context,
10+
utils
1011
}) => {
1112
const options = context.options[0] || {};
1213

@@ -38,7 +39,7 @@ export default iterateJsdoc(({
3839
return;
3940
}
4041

41-
const tags = jsdoc.tags.filter(({tag}) => {
42+
const tags = utils.filterTags(({tag}) => {
4243
return tagsWithDescriptions.includes(tag) &&
4344
{}.hasOwnProperty.call(options.tags, tag) && options.tags[tag];
4445
});

src/rules/noUndefinedTypes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const extraTypes = [
99

1010
export default iterateJsdoc(({
1111
context,
12-
jsdoc,
1312
report,
1413
sourceCode,
1514
utils
@@ -54,7 +53,7 @@ export default iterateJsdoc(({
5453
.concat(extraTypes)
5554
.concat(typedefDeclarations);
5655

57-
const jsdocTags = jsdoc.tags.filter((tag) => {
56+
const jsdocTags = utils.filterTags((tag) => {
5857
return utils.isTagWithType(tag.tag);
5958
});
6059

test/rules/assertions/noUndefinedTypes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ export default {
166166
callback();
167167
}
168168
`
169+
},
170+
{
171+
code: `
172+
/**
173+
*
174+
*
175+
*/
176+
function foo () {
177+
178+
}
179+
`
169180
}
170181
]
171182
};

0 commit comments

Comments
 (0)