diff --git a/src/rules/validTypes.js b/src/rules/validTypes.js index dd6f1e8a4..1e162b1f6 100644 --- a/src/rules/validTypes.js +++ b/src/rules/validTypes.js @@ -18,14 +18,26 @@ export default iterateJsdoc(({ } catch (err) { let error = err; - if (tagName && ['memberof', 'memberof!'].includes(tagName)) { - const endChar = type.slice(-1); - if (['#', '.', '~'].includes(endChar)) { - try { - parse(type.slice(0, -1)); - error = {}; - } catch (memberofError) { - // Use the original error for including the whole type + if (tagName) { + if (['memberof', 'memberof!'].includes(tagName)) { + const endChar = type.slice(-1); + if (['#', '.', '~'].includes(endChar)) { + try { + parse(type.slice(0, -1)); + error = {}; + } catch (memberofError) { + // Use the original error for including the whole type + } + } + } else if (tagName === 'borrows') { + const startChar = type.charAt(); + if (['#', '.', '~'].includes(startChar)) { + try { + parse(type.slice(1)); + error = {}; + } catch (memberofError) { + // Use the original error for including the whole type + } } } } @@ -49,7 +61,7 @@ export default iterateJsdoc(({ return; } - if (validTypeParsing(thisNamepath)) { + if (validTypeParsing(thisNamepath, 'borrows')) { const thatNamepath = tag.name; validTypeParsing(thatNamepath); diff --git a/test/rules/assertions/validTypes.js b/test/rules/assertions/validTypes.js index 51eafdd61..a676d4b6f 100644 --- a/test/rules/assertions/validTypes.js +++ b/test/rules/assertions/validTypes.js @@ -62,6 +62,20 @@ export default { message: 'Syntax error in type: foo%' }] }, + { + code: ` + /** + * @borrows #foo as bar + */ + function quux() { + + } + `, + errors: [{ + line: 3, + message: 'Syntax error in type: #foo' + }] + }, { code: ` /** @@ -198,6 +212,16 @@ export default { } ` }, + { + code: ` + /** + * @borrows foo as #bar + */ + function quux() { + + } + ` + }, { code: ` /**