Skip to content

Commit 35df873

Browse files
committed
fix(valid-types): liberalize to allow second path to @borrows to be a name path beginning only with a name path operator, as jsdoc accepts
This is essentially allowing jsdoctypeparser's `memberPartWithOperators` here.
1 parent f28f87f commit 35df873

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

src/rules/validTypes.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@ export default iterateJsdoc(({
1818
} catch (err) {
1919
let error = err;
2020

21-
if (tagName && ['memberof', 'memberof!'].includes(tagName)) {
22-
const endChar = type.slice(-1);
23-
if (['#', '.', '~'].includes(endChar)) {
24-
try {
25-
parse(type.slice(0, -1));
26-
error = {};
27-
} catch (memberofError) {
28-
// Use the original error for including the whole type
21+
if (tagName) {
22+
if (['memberof', 'memberof!'].includes(tagName)) {
23+
const endChar = type.slice(-1);
24+
if (['#', '.', '~'].includes(endChar)) {
25+
try {
26+
parse(type.slice(0, -1));
27+
error = {};
28+
} catch (memberofError) {
29+
// Use the original error for including the whole type
30+
}
31+
}
32+
} else if (tagName === 'borrows') {
33+
const startChar = type.charAt();
34+
if (['#', '.', '~'].includes(startChar)) {
35+
try {
36+
parse(type.slice(1));
37+
error = {};
38+
} catch (memberofError) {
39+
// Use the original error for including the whole type
40+
}
2941
}
3042
}
3143
}
@@ -49,7 +61,7 @@ export default iterateJsdoc(({
4961
return;
5062
}
5163

52-
if (validTypeParsing(thisNamepath)) {
64+
if (validTypeParsing(thisNamepath, 'borrows')) {
5365
const thatNamepath = tag.name;
5466

5567
validTypeParsing(thatNamepath);

test/rules/assertions/validTypes.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ export default {
6262
message: 'Syntax error in type: foo%'
6363
}]
6464
},
65+
{
66+
code: `
67+
/**
68+
* @borrows #foo as bar
69+
*/
70+
function quux() {
71+
72+
}
73+
`,
74+
errors: [{
75+
line: 3,
76+
message: 'Syntax error in type: #foo'
77+
}]
78+
},
6579
{
6680
code: `
6781
/**
@@ -198,6 +212,16 @@ export default {
198212
}
199213
`
200214
},
215+
{
216+
code: `
217+
/**
218+
* @borrows foo as #bar
219+
*/
220+
function quux() {
221+
222+
}
223+
`
224+
},
201225
{
202226
code: `
203227
/**

0 commit comments

Comments
 (0)