Skip to content

Commit

Permalink
fix(check-types, no-undefined-types): safer optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Mar 28, 2022
1 parent 7dbdd9f commit 63a96ee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/jsdocUtils.js
Expand Up @@ -677,12 +677,12 @@ const tagMissingRequiredTypeOrNamepath = (tag, tagMap = tagStructure) => {
* @returns {boolean}
*/
const isNewPromiseExpression = (node) => {
return node.type === 'NewExpression' && node.callee.type === 'Identifier' &&
return node && node.type === 'NewExpression' && node.callee.type === 'Identifier' &&
node.callee.name === 'Promise';
};

const isVoidPromise = (node) => {
return node.typeParameters?.params?.[0]?.type === 'TSVoidKeyword';
return node?.typeParameters?.params?.[0]?.type === 'TSVoidKeyword';
};

/**
Expand Down Expand Up @@ -716,7 +716,7 @@ const hasReturnValue = (node, promFilter) => {
case 'FunctionExpression':
case 'FunctionDeclaration':
case 'ArrowFunctionExpression': {
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node?.body)) ||
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node.body)) ||
hasReturnValue(node.body, promFilter);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/checkTypes.js
Expand Up @@ -205,7 +205,7 @@ export default iterateJsdoc(({
// parent object without a parent match (and not
// `unifyParentAndChildTypeChecks`) and we don't want
// `object<>` given TypeScript issue https://github.com/microsoft/TypeScript/issues/20555
parentNode?.elements.length && (
parentNode?.elements?.length && (
parentNode?.left?.type === 'JsdocTypeName' &&
parentNode?.left?.value === 'Object'
)
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUndefinedTypes.js
Expand Up @@ -126,7 +126,7 @@ export default iterateJsdoc(({

// In modules, including Node, there is a global scope at top with the
// Program scope inside
const cjsOrESMScope = globalScope.childScopes[0]?.block.type === 'Program';
const cjsOrESMScope = globalScope.childScopes[0]?.block?.type === 'Program';

const allDefinedTypes = new Set(globalScope.variables.map(({
name,
Expand Down

0 comments on commit 63a96ee

Please sign in to comment.