From ea76276391837ae47483895fc718be3f47ba4dfd Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 21 Jan 2022 07:52:41 +0800 Subject: [PATCH] fix: allow `Program` for `isGetter`/`isSetter` checks; fixes #832 --- src/jsdocUtils.js | 4 ++-- test/rules/assertions/requireReturns.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/jsdocUtils.js b/src/jsdocUtils.js index e31c2e6f7..179f77122 100644 --- a/src/jsdocUtils.js +++ b/src/jsdocUtils.js @@ -1298,11 +1298,11 @@ const isConstructor = (node) => { }; const isGetter = (node) => { - return node && node.parent.kind === 'get'; + return node && node.parent?.kind === 'get'; }; const isSetter = (node) => { - return node && node.parent.kind === 'set'; + return node && node.parent?.kind === 'set'; }; const hasAccessorPair = (node) => { diff --git a/test/rules/assertions/requireReturns.js b/test/rules/assertions/requireReturns.js index 665185ab5..3e0dfb35d 100644 --- a/test/rules/assertions/requireReturns.js +++ b/test/rules/assertions/requireReturns.js @@ -2472,5 +2472,26 @@ export default { ecmaVersion: 8, }, }, + { + code: ` + /** Enumerates possible genders for a product's target demographic. */ + enum Gender { + Unisex, + Mens, + Women + } + + export default Gender; + `, + ignoreReadme: true, + options: [ + { + contexts: [ + ':not(:matches(VariableDeclarator))', + ], + }, + ], + parser: require.resolve('@typescript-eslint/parser'), + }, ], };