Skip to content

Commit

Permalink
fix(valid-types): liberalize to allow second path to @borrows to be a…
Browse files Browse the repository at this point in the history
… name path beginning only with a name path operator, as jsdoc accepts

This is essentially allowing jsdoctypeparser's `memberPartWithOperators` here.
  • Loading branch information
brettz9 committed Jun 27, 2019
1 parent f28f87f commit 35df873
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/rules/validTypes.js
Expand Up @@ -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
}
}
}
}
Expand All @@ -49,7 +61,7 @@ export default iterateJsdoc(({
return;
}

if (validTypeParsing(thisNamepath)) {
if (validTypeParsing(thisNamepath, 'borrows')) {
const thatNamepath = tag.name;

validTypeParsing(thatNamepath);
Expand Down
24 changes: 24 additions & 0 deletions test/rules/assertions/validTypes.js
Expand Up @@ -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: `
/**
Expand Down Expand Up @@ -198,6 +212,16 @@ export default {
}
`
},
{
code: `
/**
* @borrows foo as #bar
*/
function quux() {
}
`
},
{
code: `
/**
Expand Down

0 comments on commit 35df873

Please sign in to comment.