Skip to content

Commit

Permalink
refactor: Move isConstructor, isGetter, and isSetter to jsdocUt…
Browse files Browse the repository at this point in the history
…ils to allow use in non-iterateJsdoc files
  • Loading branch information
brettz9 committed Jul 2, 2020
1 parent ef35f91 commit d7a669b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
16 changes: 16 additions & 0 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -779,7 +792,10 @@ export default {
hasReturnValue,
hasTag,
hasThrowValue,
isConstructor,
isGetter,
isNamepathDefiningTag,
isSetter,
isValidTag,
parseClosureTemplateTag,
tagMightHaveEitherTypeOrNamePosition,
Expand Down

0 comments on commit d7a669b

Please sign in to comment.