From 35df8737784ef9b02336f52371448c2544a7bad2 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Thu, 27 Jun 2019 14:19:26 +0800 Subject: [PATCH] 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. --- src/rules/validTypes.js | 30 ++++++++++++++++++++--------- test/rules/assertions/validTypes.js | 24 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) 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: ` /**