Skip to content

Commit

Permalink
fix: allow @memberof and @memberof! to have a trailing member ope…
Browse files Browse the repository at this point in the history
…rator after their path

These tags may have `#`, `.`, or `~` after the namepath.
  • Loading branch information
brettz9 committed Jun 11, 2019
1 parent 40f6529 commit a949094
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .README/rules/valid-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
`false` as these tags might have some indicative value without a path
or may allow a name expressed elsewhere on the block (but sets 1 and 3 will
always fail if empty)
- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`, check that both namepaths are present and valid and ensure there is an `as ` between them.
- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`,
check that both namepaths are present and valid and ensure there is an `as `
between them.
- For the special case of `@memberof` and `@memberof!` (part of set 3), as
per the [specification](https://jsdoc.app/tags-memberof.html), they also
allow `#`, `.`, or `~` at the end (which is not allowed at the end of
normal paths).

|||
|---|---|
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4896,7 +4896,13 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
`false` as these tags might have some indicative value without a path
or may allow a name expressed elsewhere on the block (but sets 1 and 3 will
always fail if empty)
- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`, check that both namepaths are present and valid and ensure there is an `as ` between them.
- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`,
check that both namepaths are present and valid and ensure there is an `as `
between them.
- For the special case of `@memberof` and `@memberof!` (part of set 3), as
per the [specification](https://jsdoc.app/tags-memberof.html), they also
allow `#`, `.`, or `~` at the end (which is not allowed at the end of
normal paths).

|||
|---|---|
Expand Down Expand Up @@ -4958,6 +4964,14 @@ function quux() {
}
// Message: Syntax error in type: module:abc#event:foo-bar

/**
* @mixes module:namespace.SomeClass~
*/
function quux() {

}
// Message: Syntax error in type: module:namespace.SomeClass~

/**
* @callback
*/
Expand Down Expand Up @@ -5040,6 +5054,20 @@ function quux() {
*/
function quux() {

}

/**
* @memberof module:namespace.SomeClass~
*/
function quux() {

}

/**
* @memberof! module:namespace.SomeClass.
*/
function quux() {

}
````

Expand Down
21 changes: 18 additions & 3 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ export default iterateJsdoc(({
return;
}
jsdoc.tags.forEach((tag) => {
const validTypeParsing = function (type) {
const validTypeParsing = function (type, tagName) {
try {
parse(type);
} catch (error) {
} catch (err) {
let error = err;

let endChar;
if (tagName && ['memberof', 'memberof!'].includes(tagName)) {
endChar = type.slice(-1);
if (['#', '.', '~'].includes(endChar)) {
try {
parse(type.slice(0, -1));
error = {};
} catch (memberofError) {
error = memberofError;
}
}
}

if (error.name === 'SyntaxError') {
report('Syntax error in type: ' + type, null, tag);

Expand Down Expand Up @@ -44,7 +59,7 @@ export default iterateJsdoc(({
if (utils.passesEmptyNamepathCheck(tag)) {
return;
}
validTypeParsing(tag.name);
validTypeParsing(tag.name, tag.tag);
} else if (tag.type && utils.isTagWithType(tag.tag)) {
validTypeParsing(tag.type);
}
Expand Down
34 changes: 34 additions & 0 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ export default {
message: 'Syntax error in type: module:abc#event:foo-bar'
}]
},
{
code: `
/**
* @mixes module:namespace.SomeClass~
*/
function quux() {
}
`,
errors: [{
line: 3,
message: 'Syntax error in type: module:namespace.SomeClass~'
}]
},
{
code: `
/**
Expand Down Expand Up @@ -210,6 +224,26 @@ export default {
*/
function quux() {
}
`
},
{
code: `
/**
* @memberof module:namespace.SomeClass~
*/
function quux() {
}
`
},
{
code: `
/**
* @memberof! module:namespace.SomeClass.
*/
function quux() {
}
`
}
Expand Down

0 comments on commit a949094

Please sign in to comment.