Skip to content

Commit a949094

Browse files
committed
fix: allow @memberof and @memberof! to have a trailing member operator after their path
These tags may have `#`, `.`, or `~` after the namepath.
1 parent 40f6529 commit a949094

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

.README/rules/valid-types.md

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

2834
|||
2935
|---|---|

README.md

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

49014907
|||
49024908
|---|---|
@@ -4958,6 +4964,14 @@ function quux() {
49584964
}
49594965
// Message: Syntax error in type: module:abc#event:foo-bar
49604966

4967+
/**
4968+
* @mixes module:namespace.SomeClass~
4969+
*/
4970+
function quux() {
4971+
4972+
}
4973+
// Message: Syntax error in type: module:namespace.SomeClass~
4974+
49614975
/**
49624976
* @callback
49634977
*/
@@ -5040,6 +5054,20 @@ function quux() {
50405054
*/
50415055
function quux() {
50425056

5057+
}
5058+
5059+
/**
5060+
* @memberof module:namespace.SomeClass~
5061+
*/
5062+
function quux() {
5063+
5064+
}
5065+
5066+
/**
5067+
* @memberof! module:namespace.SomeClass.
5068+
*/
5069+
function quux() {
5070+
50435071
}
50445072
````
50455073

src/rules/validTypes.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@ export default iterateJsdoc(({
1212
return;
1313
}
1414
jsdoc.tags.forEach((tag) => {
15-
const validTypeParsing = function (type) {
15+
const validTypeParsing = function (type, tagName) {
1616
try {
1717
parse(type);
18-
} catch (error) {
18+
} catch (err) {
19+
let error = err;
20+
21+
let endChar;
22+
if (tagName && ['memberof', 'memberof!'].includes(tagName)) {
23+
endChar = type.slice(-1);
24+
if (['#', '.', '~'].includes(endChar)) {
25+
try {
26+
parse(type.slice(0, -1));
27+
error = {};
28+
} catch (memberofError) {
29+
error = memberofError;
30+
}
31+
}
32+
}
33+
1934
if (error.name === 'SyntaxError') {
2035
report('Syntax error in type: ' + type, null, tag);
2136

@@ -44,7 +59,7 @@ export default iterateJsdoc(({
4459
if (utils.passesEmptyNamepathCheck(tag)) {
4560
return;
4661
}
47-
validTypeParsing(tag.name);
62+
validTypeParsing(tag.name, tag.tag);
4863
} else if (tag.type && utils.isTagWithType(tag.tag)) {
4964
validTypeParsing(tag.type);
5065
}

test/rules/assertions/validTypes.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ export default {
9191
message: 'Syntax error in type: module:abc#event:foo-bar'
9292
}]
9393
},
94+
{
95+
code: `
96+
/**
97+
* @mixes module:namespace.SomeClass~
98+
*/
99+
function quux() {
100+
101+
}
102+
`,
103+
errors: [{
104+
line: 3,
105+
message: 'Syntax error in type: module:namespace.SomeClass~'
106+
}]
107+
},
94108
{
95109
code: `
96110
/**
@@ -210,6 +224,26 @@ export default {
210224
*/
211225
function quux() {
212226
227+
}
228+
`
229+
},
230+
{
231+
code: `
232+
/**
233+
* @memberof module:namespace.SomeClass~
234+
*/
235+
function quux() {
236+
237+
}
238+
`
239+
},
240+
{
241+
code: `
242+
/**
243+
* @memberof! module:namespace.SomeClass.
244+
*/
245+
function quux() {
246+
213247
}
214248
`
215249
}

0 commit comments

Comments
 (0)