Skip to content

Commit

Permalink
refactor: Extract out a new exemptSpeciaMethods into jsdocUtils for…
Browse files Browse the repository at this point in the history
… potential use outside of iterateJsdoc
  • Loading branch information
brettz9 committed Jul 2, 2020
1 parent d7a669b commit b8f7060
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
31 changes: 3 additions & 28 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ const getUtils = (
return jsdocUtils.isConstructor(node);
};

utils.isGetter = () => {
return jsdocUtils.isGetter(node);
};

utils.isSetter = () => {
return jsdocUtils.isSetter(node);
};

utils.getJsdocTagsDeep = (tagName) => {
const name = utils.getPreferredTagName({tagName});
if (!name) {
Expand Down Expand Up @@ -240,14 +232,6 @@ const getUtils = (
return jsdocUtils.hasTag(jsdoc, name);
};

const hasSchemaOption = (prop) => {
const schemaProperties = ruleConfig.meta.schema[0].properties;

return context.options[0]?.[prop] ??
(schemaProperties[prop] && schemaProperties[prop].default);
};

// eslint-disable-next-line complexity
utils.avoidDocs = () => {
if (
overrideReplacesDocs !== false &&
Expand All @@ -262,18 +246,9 @@ const getUtils = (
return true;
}

if (
!hasSchemaOption('checkConstructors') &&
(
utils.isConstructor() ||
utils.hasATag([
'class',
'constructor',
])) ||
!hasSchemaOption('checkGetters') &&
utils.isGetter() ||
!hasSchemaOption('checkSetters') &&
utils.isSetter()) {
if (jsdocUtils.exemptSpeciaMethods(
jsdoc, node, context, ruleConfig.meta.schema,
)) {
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,30 @@ const isSetter = (node) => {
return node && node.parent.kind === 'set';
};

const exemptSpeciaMethods = (jsdoc, node, context, schema) => {
const hasSchemaOption = (prop) => {
const schemaProperties = schema[0].properties;

return context.options[0]?.[prop] ??
(schemaProperties[prop] && schemaProperties[prop].default);
};

return !hasSchemaOption('checkConstructors') &&
(
isConstructor(node) ||
hasATag(jsdoc, [
'class',
'constructor',
])) ||
!hasSchemaOption('checkGetters') &&
isGetter(node) ||
!hasSchemaOption('checkSetters') &&
isSetter(node);
};

export default {
enforcedContexts,
exemptSpeciaMethods,
filterTags,
flattenRoots,
getContextObject,
Expand Down

0 comments on commit b8f7060

Please sign in to comment.