Skip to content

Commit

Permalink
fix(require-template, check-template-names): avoid erring out wit…
Browse files Browse the repository at this point in the history
…h missing or bad typedef type; partial fix for gajus#1269
  • Loading branch information
brettz9 committed Jul 20, 2024
1 parent 6fb0b3e commit 736a23b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/rules/check-template-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ export type Extras<D, U, V> = [D, U, V | undefined];
* @typedef {[D, U, V | undefined]} Extras
* @typedef {[D, U, V | undefined]} Extras
*/

/**
* @typedef Foo
* @prop {string} bar
*/
````

5 changes: 5 additions & 0 deletions docs/rules/require-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,10 @@ export type Extras<D, U, V> = [D, U, V | undefined];
* @typedef {[D, U, V | undefined]} Extras
* @typedef {[D, U, V | undefined]} Extras
*/

/**
* @typedef Foo
* @prop {string} bar
*/
````

13 changes: 10 additions & 3 deletions src/rules/checkTemplateNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@ export default iterateJsdoc(({
}

const potentialType = typedefTags[0].type;
const parsedType = mode === 'permissive' ?
tryParseType(/** @type {string} */ (potentialType)) :
parseType(/** @type {string} */ (potentialType), mode)

let parsedType;
try {
parsedType = mode === 'permissive' ?
tryParseType(/** @type {string} */ (potentialType)) :
parseType(/** @type {string} */ (potentialType), mode)
} catch {
// Todo: Should handle types in @prop/erty
return;
}

traverse(parsedType, (nde) => {
const {
Expand Down
13 changes: 10 additions & 3 deletions src/rules/requireTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ export default iterateJsdoc(({
}

const potentialType = typedefTags[0].type;
const parsedType = mode === 'permissive' ?
tryParseType(/** @type {string} */ (potentialType)) :
parseType(/** @type {string} */ (potentialType), mode)

let parsedType;
try {
parsedType = mode === 'permissive' ?
tryParseType(/** @type {string} */ (potentialType)) :
parseType(/** @type {string} */ (potentialType), mode)
} catch {
// Todo: Should handle types in @prop/erty
return;
}

traverse(parsedType, (nde) => {
const {
Expand Down
8 changes: 8 additions & 0 deletions test/rules/assertions/checkTemplateNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,13 @@ export default {
*/
`,
},
{
code: `
/**
* @typedef Foo
* @prop {string} bar
*/
`,
},
],
};
8 changes: 8 additions & 0 deletions test/rules/assertions/requireTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,13 @@ export default {
*/
`,
},
{
code: `
/**
* @typedef Foo
* @prop {string} bar
*/
`,
},
],
};

0 comments on commit 736a23b

Please sign in to comment.