Skip to content

Commit 9306a52

Browse files
committed
- Refactoring: For no-undefined-types, rename tagsWithNames check to isNamepathDefiningTag
- Refactoring: For `check-types`, move tag with type check to utils - Refactoring: For `valid-types`, rename util (`isNamepathType -> `isNamepathTag`)
1 parent a9e1d13 commit 9306a52

File tree

5 files changed

+88
-57
lines changed

5 files changed

+88
-57
lines changed

src/iterateJsdoc.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,16 @@ const curryUtils = (
141141
utils.isAugmentsExtendsAllowedWithoutParam = () => {
142142
return allowAugmentsExtendsWithoutParam;
143143
};
144-
utils.isNamepathType = (tagName) => {
145-
return jsdocUtils.isNamepathType(tagName, checkSeesForNamepaths);
144+
145+
utils.isNamepathDefiningTag = (tagName) => {
146+
return jsdocUtils.isNamepathDefiningTag(tagName);
147+
};
148+
utils.isNamepathTag = (tagName) => {
149+
return jsdocUtils.isNamepathTag(tagName, checkSeesForNamepaths);
150+
};
151+
152+
utils.isTagWithType = (tagName) => {
153+
return jsdocUtils.isTagWithType(tagName);
146154
};
147155

148156
utils.avoidExampleOnConstructors = () => {

src/jsdocUtils.js

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,91 @@ const hasDefinedTypeReturnTag = (tag) => {
117117
return true;
118118
};
119119

120-
const namepathAsNameTags = [
120+
const namepathDefiningTags = [
121+
// NOT USEFUL WITHOUT NAMEPATH
122+
'class', 'constructor',
123+
'constant', 'const',
124+
'external', 'host',
125+
'function', 'func', 'method',
126+
'interface',
127+
'member', 'var',
128+
'mixin',
129+
'name',
130+
'namespace',
131+
'type',
132+
'typedef',
133+
134+
// MAY BE USEFUL WITHOUT NAMEPATH
135+
'callback',
136+
'event'
137+
];
138+
139+
const namepathPointingTags = [
140+
// NOT USEFUL WITHOUT NAMEPATH
121141
'alias',
122142
'augments',
123-
'callback',
143+
144+
// `borrows` has a different format, however, so needs special parsing
145+
'borrows',
124146
'extends',
125147
'lends',
126148
'memberof',
127149
'memberof!',
128150
'mixes',
129-
'name',
130151
'this',
131152

153+
// MAY BE USEFUL WITHOUT NAMEPATH
132154
'emits',
133-
'event',
134155
'fires',
135156
'listens'
136157
];
137158

138-
const isNamepathType = (tagName, checkSeesForNamepaths) => {
139-
return namepathAsNameTags.includes(tagName) ||
159+
const isNamepathDefiningTag = (tagName) => {
160+
return namepathDefiningTags.includes(tagName);
161+
};
162+
163+
const isNamepathPointingTag = (tagName, checkSeesForNamepaths) => {
164+
return namepathPointingTags.includes(tagName) ||
140165
tagName === 'see' && checkSeesForNamepaths;
141166
};
142167

168+
const isNamepathTag = (tagName, checkSeesForNamepaths) => {
169+
return isNamepathDefiningTag(tagName) ||
170+
isNamepathPointingTag(tagName, checkSeesForNamepaths);
171+
};
172+
173+
let tagsWithTypes = [
174+
'class',
175+
'constant',
176+
'enum',
177+
'member',
178+
'module',
179+
'namespace',
180+
'param',
181+
'property',
182+
'returns',
183+
'throws',
184+
'type',
185+
'typedef'
186+
];
187+
188+
const tagsWithTypesAliases = [
189+
'constructor',
190+
'const',
191+
'var',
192+
'arg',
193+
'argument',
194+
'prop',
195+
'return',
196+
'exception'
197+
];
198+
199+
tagsWithTypes = tagsWithTypes.concat(tagsWithTypesAliases);
200+
201+
const isTagWithType = (tagName) => {
202+
return tagsWithTypes.includes(tagName);
203+
};
204+
143205
const LOOP_STATEMENTS = ['WhileStatement', 'DoWhileStatement', 'ForStatement', 'ForInStatement', 'ForOfStatement'];
144206

145207
const STATEMENTS_WITH_CHILDREN = [
@@ -365,6 +427,8 @@ export default {
365427
hasDefinedTypeReturnTag,
366428
hasReturnValue,
367429
hasTag,
368-
isNamepathType,
430+
isNamepathDefiningTag,
431+
isNamepathTag,
432+
isTagWithType,
369433
isValidTag
370434
};

src/rules/checkTypes.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,6 @@
11
import {parse, traverse, publish} from 'jsdoctypeparser';
22
import iterateJsdoc from '../iterateJsdoc';
33

4-
let targetTags = [
5-
'class',
6-
'constant',
7-
'enum',
8-
'member',
9-
'module',
10-
'namespace',
11-
'param',
12-
'property',
13-
'returns',
14-
'throws',
15-
'type',
16-
'typedef'
17-
];
18-
19-
const targetTagAliases = [
20-
'constructor',
21-
'const',
22-
'var',
23-
'arg',
24-
'argument',
25-
'prop',
26-
'return',
27-
'exception'
28-
];
29-
30-
targetTags = targetTags.concat(targetTagAliases);
31-
324
const strictNativeTypes = [
335
'undefined',
346
'null',
@@ -46,10 +18,11 @@ export default iterateJsdoc(({
4618
jsdoc,
4719
jsdocNode,
4820
sourceCode,
49-
report
21+
report,
22+
utils
5023
}) => {
5124
const jsdocTags = jsdoc.tags.filter((tag) => {
52-
return targetTags.includes(tag.tag);
25+
return utils.isTagWithType(tag.tag);
5326
});
5427

5528
jsdocTags.forEach((jsdocTag) => {

src/rules/noUndefinedTypes.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,13 @@ const extraTypes = [
66
'null', 'undefined', 'string', 'number', 'boolean', 'any', '*',
77
'Array', 'Object', 'RegExp', 'Date', 'Function'
88
];
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-
];
249

2510
export default iterateJsdoc(({
2611
context,
2712
jsdoc,
2813
report,
29-
sourceCode
14+
sourceCode,
15+
utils
3016
}) => {
3117
const scopeManager = sourceCode.scopeManager;
3218
const globalScope = scopeManager.globalScope;
@@ -38,7 +24,7 @@ export default iterateJsdoc(({
3824
.map(parseComment)
3925
.flatMap((doc) => {
4026
return (doc.tags || []).filter(({tag}) => {
41-
return tagsWithNames.includes(tag);
27+
return utils.isNamepathDefiningTag(tag);
4228
});
4329
})
4430
.map((tag) => {

src/rules/validTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default iterateJsdoc(({
4242

4343
validTypeParsing(thatNamepath);
4444
}
45-
} else if (utils.isNamepathType(tag.tag)) {
45+
} else if (utils.isNamepathTag(tag.tag)) {
4646
if (utils.passesEmptyNamepathCheck(tag)) {
4747
return;
4848
}

0 commit comments

Comments
 (0)