Skip to content

Commit

Permalink
fix(valid-types): report problems with name parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Oct 23, 2022
1 parent 87841e8 commit e247d67
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22332,6 +22332,39 @@ function quux () {}
function quux () {}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Syntax error in supresss type: blah

/**
* @param {Object[]} employees
* @param {string} employees[.name - The name of an employee.
*/
function quux () {}
// Message: Invalid name: unpaired brackets

/**
* @param {Object[]} employees
* @param {string} [] - The name of an employee.
*/
function quux () {}
// Message: Invalid name: empty name

/**
* @param {Object[]} employees
* @param {string} [] - The name of an employee.
*/
function quux () {}
// Message: Invalid name: empty name

/**
* @param {string} [name=] - The name of an employee.
*/
function quux () {}
// Message: Invalid name: empty default value

/**
* @param {string} [name==] - The name of an employee.
*/
function quux () {}
// Message: Invalid name: invalid default value syntax
````

The following patterns are not considered problems:
Expand Down
10 changes: 10 additions & 0 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ export default iterateJsdoc(({
return true;
};

if (tag.problems.length) {
const msg = tag.problems.reduce((str, {
message,
}) => {
return str + '; ' + message;
}, '').slice(2);
report(`Invalid name: ${msg}`, null, tag);
continue;
}

if (tag.tag === 'borrows') {
const thisNamepath = utils.getTagDescription(tag).replace(asExpression, '')
.trim();
Expand Down
78 changes: 78 additions & 0 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,84 @@ export default {
],
ignoreReadme: true,
},
{
code: `
/**
* @param {Object[]} employees
* @param {string} employees[.name - The name of an employee.
*/
function quux () {}
`,
errors: [
{
line: 4,
message: 'Invalid name: unpaired brackets',
},
],
},
{
code: `
/**
* @param {Object[]} employees
* @param {string} [] - The name of an employee.
*/
function quux () {}
`,
errors: [
{
line: 4,
message: 'Invalid name: empty name',
},
],
},
{
code: `
/**
* @param {Object[]} employees
* @param {string} [] - The name of an employee.
*/
function quux () {}
`,
errors: [
{
line: 4,
message: 'Invalid name: empty name',
},
],
},
{
code: `
/**
* @param {string} [name=] - The name of an employee.
*/
function quux () {}
`,
errors: [
{
line: 3,
message: 'Invalid name: empty default value',
},
],
},
{
code: `
/**
* @param {string} [name==] - The name of an employee.
*/
function quux () {}
`,
errors: [
{
line: 3,
message: 'Invalid name: invalid default value syntax',
},
],
},
],
valid: [
{
Expand Down

0 comments on commit e247d67

Please sign in to comment.