Skip to content

Commit 63a96ee

Browse files
committed
fix(check-types, no-undefined-types): safer optional chaining
1 parent 7dbdd9f commit 63a96ee

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/jsdocUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,12 @@ const tagMissingRequiredTypeOrNamepath = (tag, tagMap = tagStructure) => {
677677
* @returns {boolean}
678678
*/
679679
const isNewPromiseExpression = (node) => {
680-
return node.type === 'NewExpression' && node.callee.type === 'Identifier' &&
680+
return node && node.type === 'NewExpression' && node.callee.type === 'Identifier' &&
681681
node.callee.name === 'Promise';
682682
};
683683

684684
const isVoidPromise = (node) => {
685-
return node.typeParameters?.params?.[0]?.type === 'TSVoidKeyword';
685+
return node?.typeParameters?.params?.[0]?.type === 'TSVoidKeyword';
686686
};
687687

688688
/**
@@ -716,7 +716,7 @@ const hasReturnValue = (node, promFilter) => {
716716
case 'FunctionExpression':
717717
case 'FunctionDeclaration':
718718
case 'ArrowFunctionExpression': {
719-
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node?.body)) ||
719+
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node.body)) ||
720720
hasReturnValue(node.body, promFilter);
721721
}
722722

src/rules/checkTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export default iterateJsdoc(({
205205
// parent object without a parent match (and not
206206
// `unifyParentAndChildTypeChecks`) and we don't want
207207
// `object<>` given TypeScript issue https://github.com/microsoft/TypeScript/issues/20555
208-
parentNode?.elements.length && (
208+
parentNode?.elements?.length && (
209209
parentNode?.left?.type === 'JsdocTypeName' &&
210210
parentNode?.left?.value === 'Object'
211211
)

src/rules/noUndefinedTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default iterateJsdoc(({
126126

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

131131
const allDefinedTypes = new Set(globalScope.variables.map(({
132132
name,

0 commit comments

Comments
 (0)