Skip to content

Commit bccfebe

Browse files
committed
Call namepaths namepath instead of types in error messages
1 parent 668ea89 commit bccfebe

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7345,39 +7345,39 @@ function quux() {
73457345
function quux() {
73467346

73477347
}
7348-
// Message: Syntax error in type: module:namespace.SomeClass<~
7348+
// Message: Syntax error in namepath: module:namespace.SomeClass<~
73497349

73507350
/**
73517351
* @memberof module:namespace.SomeClass~<
73527352
*/
73537353
function quux() {
73547354

73557355
}
7356-
// Message: Syntax error in type: module:namespace.SomeClass~<
7356+
// Message: Syntax error in namepath: module:namespace.SomeClass~<
73577357

73587358
/**
73597359
* @borrows foo% as bar
73607360
*/
73617361
function quux() {
73627362

73637363
}
7364-
// Message: Syntax error in type: foo%
7364+
// Message: Syntax error in namepath: foo%
73657365

73667366
/**
73677367
* @borrows #foo as bar
73687368
*/
73697369
function quux() {
73707370

73717371
}
7372-
// Message: Syntax error in type: #foo
7372+
// Message: Syntax error in namepath: #foo
73737373

73747374
/**
73757375
* @borrows foo as bar%
73767376
*/
73777377
function quux() {
73787378

73797379
}
7380-
// Message: Syntax error in type: bar%
7380+
// Message: Syntax error in namepath: bar%
73817381

73827382
/**
73837383
* @borrows foo
@@ -7394,7 +7394,7 @@ function quux() {
73947394

73957395
}
73967396
// Options: [{"checkSeesForNamepaths":true}]
7397-
// Message: Syntax error in type: foo%
7397+
// Message: Syntax error in namepath: foo%
73987398

73997399
/** */
74007400
function foo() {}
@@ -7407,15 +7407,15 @@ function foo() {}
74077407
function quux() {
74087408

74097409
}
7410-
// Message: Syntax error in type: module:abc#event:foo-bar
7410+
// Message: Syntax error in namepath: module:abc#event:foo-bar
74117411

74127412
/**
74137413
* @mixes module:namespace.SomeClass~
74147414
*/
74157415
function quux() {
74167416

74177417
}
7418-
// Message: Syntax error in type: module:namespace.SomeClass~
7418+
// Message: Syntax error in namepath: module:namespace.SomeClass~
74197419

74207420
/**
74217421
* @callback
@@ -7440,7 +7440,7 @@ function quux() {
74407440
/**
74417441
* @typedef {string} UserStr%ng
74427442
*/
7443-
// Message: Syntax error in type: UserStr%ng
7443+
// Message: Syntax error in namepath: UserStr%ng
74447444

74457445
/**
74467446
* @extends

src/rules/validTypes.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,38 @@ export default iterateJsdoc(({
2121
return;
2222
}
2323
jsdoc.tags.forEach((tag) => {
24-
const validTypeParsing = function (type, tagName) {
24+
const validNamepathParsing = function (namepath, tagName) {
2525
try {
26-
parse(type);
27-
} catch (err) {
28-
let error = err;
26+
parse(namepath);
27+
} catch (error) {
28+
let handled = false;
2929

3030
if (tagName) {
3131
if (['memberof', 'memberof!'].includes(tagName)) {
32-
const endChar = type.slice(-1);
32+
const endChar = namepath.slice(-1);
3333
if (['#', '.', '~'].includes(endChar)) {
3434
try {
35-
parse(type.slice(0, -1));
36-
error = {};
35+
parse(namepath.slice(0, -1));
36+
handled = true;
3737
} catch (memberofError) {
3838
// Use the original error for including the whole type
3939
}
4040
}
4141
} else if (tagName === 'borrows') {
42-
const startChar = type.charAt();
42+
const startChar = namepath.charAt();
4343
if (['#', '.', '~'].includes(startChar)) {
4444
try {
45-
parse(type.slice(1));
46-
error = {};
45+
parse(namepath.slice(1));
46+
handled = true;
4747
} catch (memberofError) {
4848
// Use the original error for including the whole type
4949
}
5050
}
5151
}
5252
}
5353

54-
if (error.name === 'SyntaxError') {
55-
report(`Syntax error in type: ${type}`, null, tag);
54+
if (!handled) {
55+
report(`Syntax error in namepath: ${namepath}`, null, tag);
5656

5757
return false;
5858
}
@@ -61,6 +61,18 @@ export default iterateJsdoc(({
6161
return true;
6262
};
6363

64+
const validTypeParsing = function (type) {
65+
try {
66+
parse(type);
67+
} catch (error) {
68+
report(`Syntax error in type: ${type}`, null, tag);
69+
70+
return false;
71+
}
72+
73+
return true;
74+
};
75+
6476
const hasType = utils.tagMightHaveType(tag.tag) && Boolean(tag.type);
6577
const mustHaveType = utils.tagMustHaveType(tag.tag);
6678

@@ -79,10 +91,10 @@ export default iterateJsdoc(({
7991
return;
8092
}
8193

82-
if (validTypeParsing(thisNamepath, 'borrows')) {
94+
if (validNamepathParsing(thisNamepath, 'borrows')) {
8395
const thatNamepath = tag.name;
8496

85-
validTypeParsing(thatNamepath);
97+
validNamepathParsing(thatNamepath);
8698
}
8799
} else {
88100
if (mustHaveEither && !hasEither) {
@@ -98,7 +110,7 @@ export default iterateJsdoc(({
98110
}
99111

100112
if (hasNamePath) {
101-
validTypeParsing(tag.name, tag.tag);
113+
validNamepathParsing(tag.name, tag.tag);
102114
} else if (mustHaveNamepath) {
103115
report(`Tag @${tag.tag} must have a namepath`, null, tag);
104116
}

test/rules/assertions/validTypes.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
errors: [
2929
{
3030
line: 3,
31-
message: 'Syntax error in type: module:namespace.SomeClass<~',
31+
message: 'Syntax error in namepath: module:namespace.SomeClass<~',
3232
},
3333
],
3434
},
@@ -44,7 +44,7 @@ export default {
4444
errors: [
4545
{
4646
line: 3,
47-
message: 'Syntax error in type: module:namespace.SomeClass~<',
47+
message: 'Syntax error in namepath: module:namespace.SomeClass~<',
4848
},
4949
],
5050
},
@@ -59,7 +59,7 @@ export default {
5959
`,
6060
errors: [{
6161
line: 3,
62-
message: 'Syntax error in type: foo%',
62+
message: 'Syntax error in namepath: foo%',
6363
}],
6464
},
6565
{
@@ -73,7 +73,7 @@ export default {
7373
`,
7474
errors: [{
7575
line: 3,
76-
message: 'Syntax error in type: #foo',
76+
message: 'Syntax error in namepath: #foo',
7777
}],
7878
},
7979
{
@@ -87,7 +87,7 @@ export default {
8787
`,
8888
errors: [{
8989
line: 3,
90-
message: 'Syntax error in type: bar%',
90+
message: 'Syntax error in namepath: bar%',
9191
}],
9292
},
9393
{
@@ -115,7 +115,7 @@ export default {
115115
`,
116116
errors: [{
117117
line: 3,
118-
message: 'Syntax error in type: foo%',
118+
message: 'Syntax error in namepath: foo%',
119119
}],
120120
options: [{
121121
checkSeesForNamepaths: true,
@@ -152,7 +152,7 @@ export default {
152152
`,
153153
errors: [{
154154
line: 3,
155-
message: 'Syntax error in type: module:abc#event:foo-bar',
155+
message: 'Syntax error in namepath: module:abc#event:foo-bar',
156156
}],
157157
},
158158
{
@@ -166,7 +166,7 @@ export default {
166166
`,
167167
errors: [{
168168
line: 3,
169-
message: 'Syntax error in type: module:namespace.SomeClass~',
169+
message: 'Syntax error in namepath: module:namespace.SomeClass~',
170170
}],
171171
},
172172
{
@@ -222,7 +222,7 @@ export default {
222222
errors: [
223223
{
224224
line: 3,
225-
message: 'Syntax error in type: UserStr%ng',
225+
message: 'Syntax error in namepath: UserStr%ng',
226226
},
227227
],
228228
},

0 commit comments

Comments
 (0)