From d7a669bbefdb5f3dba6576ab9bffe6462f1b1b46 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Thu, 2 Jul 2020 15:46:01 +0800 Subject: [PATCH] refactor: Move `isConstructor`, `isGetter`, and `isSetter` to jsdocUtils to allow use in non-iterateJsdoc files --- src/iterateJsdoc.js | 7 +++---- src/jsdocUtils.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index 6311a7dc4..3bba7c928 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -189,16 +189,15 @@ const getUtils = ( }; utils.isConstructor = () => { - return node?.type === 'MethodDefinition' && node.kind === 'constructor' || - node?.parent?.kind === 'constructor'; + return jsdocUtils.isConstructor(node); }; utils.isGetter = () => { - return node && node.parent.kind === 'get'; + return jsdocUtils.isGetter(node); }; utils.isSetter = () => { - return node && node.parent.kind === 'set'; + return jsdocUtils.isSetter(node); }; utils.getJsdocTagsDeep = (tagName) => { diff --git a/src/jsdocUtils.js b/src/jsdocUtils.js index ed1196edd..59ac2b8ec 100644 --- a/src/jsdocUtils.js +++ b/src/jsdocUtils.js @@ -764,6 +764,19 @@ const getIndent = (sourceCode) => { return indent; }; +const isConstructor = (node) => { + return node?.type === 'MethodDefinition' && node.kind === 'constructor' || + node?.parent?.kind === 'constructor'; +}; + +const isGetter = (node) => { + return node && node.parent.kind === 'get'; +}; + +const isSetter = (node) => { + return node && node.parent.kind === 'set'; +}; + export default { enforcedContexts, filterTags, @@ -779,7 +792,10 @@ export default { hasReturnValue, hasTag, hasThrowValue, + isConstructor, + isGetter, isNamepathDefiningTag, + isSetter, isValidTag, parseClosureTemplateTag, tagMightHaveEitherTypeOrNamePosition,