Skip to content

Commit f5ba20b

Browse files
SulimanAbdulrazzaqbrettz9
authored andcommitted
fix(check-param-names, require-jsdoc, convert-to-jsdoc-comments): do not throw on settings.jsdoc.contexts entries the rule cannot handle
1 parent 6f90f25 commit f5ba20b

6 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎docs/rules/check-param-names.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,5 +1360,8 @@ const emit = defineEmits<{
13601360
*/
13611361
submitField: [index: number];
13621362
}>();
1363+
1364+
/** @typedef {string} Foo */
1365+
// Settings: {"jsdoc":{"contexts":["any"]}}
13631366
````
13641367

‎docs/rules/require-jsdoc.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,5 +2237,10 @@ const obj = {
22372237
export default wrap(function () {
22382238
});
22392239
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
2240+
2241+
/** Doc */
2242+
function quux () {
2243+
}
2244+
// Settings: {"jsdoc":{"contexts":[{"comment":"JsdocBlock","context":"FunctionDeclaration"}]}}
22402245
````
22412246

‎src/jsdocUtils.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ const getContextObject = (contexts, checkJsdoc, handler, convertAny) => {
17071707
lastIndex: idx,
17081708
selector: prop.context,
17091709
};
1710-
if (prop.comment) {
1710+
if (prop.comment && handler) {
17111711
property = /** @type {string} */ (prop.context);
17121712
value = checkJsdoc.bind(
17131713
null,

‎src/rules/checkParamNames.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ export default iterateJsdoc(({
648648
// checks if they are not functions but say variables), the user may
649649
// instead wish to narrow contexts in those settings, so this check
650650
// is still useful
651-
if (!allowedNodes.includes(nde.type) ||
651+
if (!nde || !allowedNodes.includes(nde.type) ||
652652
nde.type === 'TSPropertySignature' &&
653653
(/** @type {import('@typescript-eslint/types').TSESTree.TSPropertySignature} */ (
654654
nde

‎test/rules/assertions/checkParamNames.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,5 +2464,17 @@ export default /** @type {import('../index.js').TestCases} */ ({
24642464
parser: typescriptEslintParser,
24652465
},
24662466
},
2467+
{
2468+
code: `
2469+
/** @typedef {string} Foo */
2470+
`,
2471+
settings: {
2472+
jsdoc: {
2473+
contexts: [
2474+
'any',
2475+
],
2476+
},
2477+
},
2478+
},
24672479
],
24682480
});

‎test/rules/assertions/requireJsdoc.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7017,5 +7017,22 @@ function quux (foo) {
70177017
},
70187018
],
70197019
},
7020+
{
7021+
code: `
7022+
/** Doc */
7023+
function quux () {
7024+
}
7025+
`,
7026+
settings: {
7027+
jsdoc: {
7028+
contexts: [
7029+
{
7030+
comment: 'JsdocBlock',
7031+
context: 'FunctionDeclaration',
7032+
},
7033+
],
7034+
},
7035+
},
7036+
},
70207037
],
70217038
});

0 commit comments

Comments
 (0)