Skip to content

Commit a075dec

Browse files
authored
Merge pull request #212 from brettz9/issue-210-callback
feat: allow additional types in `no-undefined-types`
2 parents ff57654 + cf31761 commit a075dec

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/rules/noUndefinedTypes.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@ import _ from 'lodash';
22
import {parse as parseType, traverse} from 'jsdoctypeparser';
33
import iterateJsdoc, {parseComment} from '../iterateJsdoc';
44

5-
const extraTypes = ['string', 'number', 'boolean', 'any', '*'];
5+
const extraTypes = [
6+
'null', 'undefined', 'string', 'number', 'boolean', 'any', '*',
7+
'Array', 'Object', 'RegExp', 'Date', 'Function'
8+
];
9+
const tagsWithNames = [
10+
'callback',
11+
'class', 'constructor',
12+
'constant', 'const',
13+
'event',
14+
'external', 'host',
15+
'function', 'func', 'method',
16+
'interface',
17+
'member', 'var',
18+
'mixin',
19+
'name',
20+
'namespace',
21+
'type',
22+
'typedef'
23+
];
624

725
export default iterateJsdoc(({
826
context,
@@ -20,7 +38,7 @@ export default iterateJsdoc(({
2038
.map(parseComment)
2139
.flatMap((doc) => {
2240
return (doc.tags || []).filter((tag) => {
23-
return tag.tag === 'typedef';
41+
return _.includes(tagsWithNames, tag.tag);
2442
});
2543
})
2644
.map((tag) => {

test/rules/assertions/noUndefinedTypes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ export default {
117117
118118
}
119119
`
120+
},
121+
{
122+
code: `
123+
/**
124+
* Callback test.
125+
*
126+
* @callback addStuffCallback
127+
* @param {String} sum - An test integer.
128+
*/
129+
/**
130+
* Test Eslint.
131+
*
132+
* @param {addStuffCallback} callback - A callback to run.
133+
*/
134+
function testFunction(callback) {
135+
callback();
136+
}
137+
`
120138
}
121139
]
122140
};

0 commit comments

Comments
 (0)