Skip to content

Commit

Permalink
fix: ensure ignorePrivate setting works with iterateAllJsdocs rules
Browse files Browse the repository at this point in the history
This impacts rules: `checkAccess`, `checkAlignment`, `checkExamples`,
`checkIndentation`, `checkSyntax`, `checkTagNames`, `checkTypes`,
`checkValues`, `emptyTags`, `newlineAfterDescription`, `noUndefinedTypes,
`requireDescriptionCompleteSentence`, `requireHyphenBeforeParamDescription`,
`validTypes

Factors out common `iterate` code. Also ensures any future rules with
`noTrim` but without `iterateAllJsdocs` will work
  • Loading branch information
brettz9 committed Dec 28, 2019
1 parent 4fce006 commit 9703aba
Showing 1 changed file with 45 additions and 50 deletions.
95 changes: 45 additions & 50 deletions src/iterateJsdoc.js
Expand Up @@ -409,6 +409,43 @@ const makeReport = (context, commentNode) => {
* ) => any } JsdocVisitor
*/

const iterate = (
ruleConfig, context, lines, jsdocNode, node, settings, sourceCode, iterator,
) => {
const sourceLine = lines[jsdocNode.loc.start.line - 1];
const indent = sourceLine.charAt(0).repeat(jsdocNode.loc.start.column);
const jsdoc = parseComment(jsdocNode, indent, !ruleConfig.noTrim);
const report = makeReport(context, jsdocNode);

const utils = getUtils(
node,
jsdoc,
jsdocNode,
settings,
report,
context,
);

if (
settings.ignorePrivate &&
utils.hasTag('private')
) {
return;
}

iterator({
context,
indent,
jsdoc,
jsdocNode,
node,
report,
settings,
sourceCode,
utils,
});
};

/**
* Create an eslint rule that iterates over all JSDocs, regardless of whether
* they are attached to a function-like node.
Expand All @@ -427,22 +464,10 @@ const iterateAllJsdocs = (iterator, ruleConfig) => {
if (!(/^\/\*\*\s/).test(sourceCode.getText(jsdocNode))) {
return;
}
const sourceLine = lines[jsdocNode.loc.start.line - 1];
const indent = sourceLine.charAt(0).repeat(jsdocNode.loc.start.column);
const jsdoc = parseComment(jsdocNode, indent, !ruleConfig.noTrim);
const report = makeReport(context, jsdocNode);

iterator({
context,
indent,
jsdoc,
jsdocNode,
node,
report,
settings,
sourceCode,
utils: getUtils(node, jsdoc, jsdocNode, settings, report, context),
});
iterate(
ruleConfig, context, lines, jsdocNode, node,
settings, sourceCode, iterator,
);
});
};

Expand Down Expand Up @@ -525,48 +550,18 @@ export default function iterateJsdoc (iterator, ruleConfig) {

const settings = getSettings(context);

const {lines} = sourceCode;
const checkJsdoc = (node) => {
const jsdocNode = getJSDocComment(sourceCode, node, settings);

if (!jsdocNode) {
return;
}

const sourceLine = sourceCode.lines[jsdocNode.loc.start.line - 1];

const indent = sourceLine.charAt(0).repeat(jsdocNode.loc.start.column);

const jsdoc = parseComment(jsdocNode, indent);

const report = makeReport(context, jsdocNode);

const utils = getUtils(
node,
jsdoc,
jsdocNode,
settings,
report,
context,
iterate(
ruleConfig, context, lines, jsdocNode, node,
settings, sourceCode, iterator,
);

if (
settings.ignorePrivate &&
utils.hasTag('private')
) {
return;
}

iterator({
context,
indent,
jsdoc,
jsdocNode,
node,
report,
settings,
sourceCode,
utils,
});
};

if (ruleConfig.contextDefaults) {
Expand Down

0 comments on commit 9703aba

Please sign in to comment.