Skip to content

Commit e247d67

Browse files
committedOct 23, 2022
fix(valid-types): report problems with name parsing
1 parent 87841e8 commit e247d67

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
 

‎README.md

+33
Original file line numberDiff line numberDiff line change
@@ -22332,6 +22332,39 @@ function quux () {}
2233222332
function quux () {}
2233322333
// Settings: {"jsdoc":{"mode":"closure"}}
2233422334
// Message: Syntax error in supresss type: blah
22335+
22336+
/**
22337+
* @param {Object[]} employees
22338+
* @param {string} employees[.name - The name of an employee.
22339+
*/
22340+
function quux () {}
22341+
// Message: Invalid name: unpaired brackets
22342+
22343+
/**
22344+
* @param {Object[]} employees
22345+
* @param {string} [] - The name of an employee.
22346+
*/
22347+
function quux () {}
22348+
// Message: Invalid name: empty name
22349+
22350+
/**
22351+
* @param {Object[]} employees
22352+
* @param {string} [] - The name of an employee.
22353+
*/
22354+
function quux () {}
22355+
// Message: Invalid name: empty name
22356+
22357+
/**
22358+
* @param {string} [name=] - The name of an employee.
22359+
*/
22360+
function quux () {}
22361+
// Message: Invalid name: empty default value
22362+
22363+
/**
22364+
* @param {string} [name==] - The name of an employee.
22365+
*/
22366+
function quux () {}
22367+
// Message: Invalid name: invalid default value syntax
2233522368
````
2233622369

2233722370
The following patterns are not considered problems:

‎src/rules/validTypes.js

+10
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ export default iterateJsdoc(({
158158
return true;
159159
};
160160

161+
if (tag.problems.length) {
162+
const msg = tag.problems.reduce((str, {
163+
message,
164+
}) => {
165+
return str + '; ' + message;
166+
}, '').slice(2);
167+
report(`Invalid name: ${msg}`, null, tag);
168+
continue;
169+
}
170+
161171
if (tag.tag === 'borrows') {
162172
const thisNamepath = utils.getTagDescription(tag).replace(asExpression, '')
163173
.trim();

‎test/rules/assertions/validTypes.js

+78
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,84 @@ export default {
974974
],
975975
ignoreReadme: true,
976976
},
977+
{
978+
code: `
979+
/**
980+
* @param {Object[]} employees
981+
* @param {string} employees[.name - The name of an employee.
982+
*/
983+
function quux () {}
984+
985+
`,
986+
errors: [
987+
{
988+
line: 4,
989+
message: 'Invalid name: unpaired brackets',
990+
},
991+
],
992+
},
993+
{
994+
code: `
995+
/**
996+
* @param {Object[]} employees
997+
* @param {string} [] - The name of an employee.
998+
*/
999+
function quux () {}
1000+
1001+
`,
1002+
errors: [
1003+
{
1004+
line: 4,
1005+
message: 'Invalid name: empty name',
1006+
},
1007+
],
1008+
},
1009+
{
1010+
code: `
1011+
/**
1012+
* @param {Object[]} employees
1013+
* @param {string} [] - The name of an employee.
1014+
*/
1015+
function quux () {}
1016+
1017+
`,
1018+
errors: [
1019+
{
1020+
line: 4,
1021+
message: 'Invalid name: empty name',
1022+
},
1023+
],
1024+
},
1025+
{
1026+
code: `
1027+
/**
1028+
* @param {string} [name=] - The name of an employee.
1029+
*/
1030+
function quux () {}
1031+
1032+
`,
1033+
errors: [
1034+
{
1035+
line: 3,
1036+
message: 'Invalid name: empty default value',
1037+
},
1038+
],
1039+
},
1040+
{
1041+
code: `
1042+
/**
1043+
* @param {string} [name==] - The name of an employee.
1044+
*/
1045+
function quux () {}
1046+
1047+
`,
1048+
errors: [
1049+
{
1050+
line: 3,
1051+
message: 'Invalid name: invalid default value syntax',
1052+
},
1053+
],
1054+
},
9771055
],
9781056
valid: [
9791057
{

0 commit comments

Comments
 (0)
Please sign in to comment.