Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/eslint-plugin-jsdoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v39.3.20
Choose a base ref
...
head repository: gajus/eslint-plugin-jsdoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v39.3.21
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Oct 23, 2022

  1. fix(require-param): do not cache by comment node; fixes #901

    May target same comment node but with different JS node (e.g., if `any` context is used, we don't want an export declaration's comment to be cached (but not used) and then this prevent the export's `FunctionDeclaration` from being evaluated
    brettz9 committed Oct 23, 2022
    Copy the full SHA
    867edc3 View commit details
Showing with 72 additions and 27 deletions.
  1. +1 −8 src/iterateJsdoc.js
  2. +28 −19 src/rules/requireParam.js
  3. +43 −0 test/rules/assertions/requireParam.js
9 changes: 1 addition & 8 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
getReducedASTNode,
getJSDocComment,
commentHandler,
parseComment,
@@ -1147,14 +1146,8 @@ const iterateAllJsdocs = (iterator, ruleConfig, contexts, additiveCommentContext

return {
'*:not(Program)' (node) {
const reducedNode = getReducedASTNode(node, sourceCode);

if (node !== reducedNode) {
return;
}

const commentNode = getJSDocComment(sourceCode, node, settings);
if (trackedJsdocs.has(commentNode)) {
if (!ruleConfig.noTracking && trackedJsdocs.has(commentNode)) {
return;
}

47 changes: 28 additions & 19 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
@@ -31,24 +31,6 @@ export default iterateJsdoc(({
utils,
context,
}) => {
const preferredTagName = utils.getPreferredTagName({
tagName: 'param',
});
if (!preferredTagName) {
return;
}

const jsdocParameterNames = utils.getJsdocTagsDeep(preferredTagName);

const shallowJsdocParameterNames = jsdocParameterNames.filter((tag) => {
return !tag.name.includes('.');
}).map((tag, idx) => {
return {
...tag,
idx,
};
});

if (utils.avoidDocs()) {
return;
}
@@ -73,10 +55,32 @@ export default iterateJsdoc(({
useDefaultObjectProperties = false,
} = context.options[0] || {};

const preferredTagName = utils.getPreferredTagName({
tagName: 'param',
});
if (!preferredTagName) {
return;
}

const functionParameterNames = utils.getFunctionParameterNames(useDefaultObjectProperties);
if (!functionParameterNames.length) {
return;
}

const jsdocParameterNames = utils.getJsdocTagsDeep(preferredTagName);

const shallowJsdocParameterNames = jsdocParameterNames.filter((tag) => {
return !tag.name.includes('.');
}).map((tag, idx) => {
return {
...tag,
idx,
};
});

const checkTypesRegex = utils.getRegexFromString(checkTypesPattern);

const missingTags = [];
const functionParameterNames = utils.getFunctionParameterNames(useDefaultObjectProperties);
const flattenedRoots = utils.flattenRoots(functionParameterNames).names;

const paramIndex = {};
@@ -486,4 +490,9 @@ export default iterateJsdoc(({
],
type: 'suggestion',
},

// We cannot cache comment nodes as the contexts may recur with the
// same comment node but a different JS node, and we may need the different
// JS node to ensure we iterate its context
noTracking: true,
});
43 changes: 43 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
@@ -2408,6 +2408,49 @@ export default {
`,
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
* Helper function to warp to a custom stage/level.
*
* @param name The name
* @param firstFloor Optional.
*/
export function setCustomStage(
name: string,
firstFloor = true,
verbose = false,
): void {}
`,
errors: [
{
message: 'Missing JSDoc @param "verbose" declaration.',
},
],
ignoreReadme: true,
options: [
{
contexts: [
'any',
],
},
],
output: `
/**
* Helper function to warp to a custom stage/level.
*
* @param name The name
* @param firstFloor Optional.
* @param verbose
*/
export function setCustomStage(
name: string,
firstFloor = true,
verbose = false,
): void {}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
valid: [
{