eslint-plugin-jsdoc 61.5.0 → 61.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,34 +12,50 @@ const validatePropertyNames = (
12
12
  enableFixer,
13
13
  jsdoc, utils,
14
14
  ) => {
15
- const propertyTags = Object.entries(jsdoc.tags).filter(([
16
- , tag,
17
- ]) => {
18
- return tag.tag === targetTagName;
19
- });
15
+ const jsdocTypedefs = utils.getJsdocTagsDeep('typedef');
16
+ let propertyTagGroups;
17
+ if (jsdocTypedefs && jsdocTypedefs.length > 1) {
18
+ propertyTagGroups = jsdocTypedefs.map(({
19
+ idx,
20
+ }, index) => {
21
+ return Object.entries(jsdoc.tags).slice(idx, jsdocTypedefs[index + 1]?.idx);
22
+ });
23
+ } else {
24
+ propertyTagGroups = [
25
+ Object.entries(jsdoc.tags),
26
+ ];
27
+ }
20
28
 
21
- return propertyTags.some(([
22
- , tag,
23
- ], index) => {
24
- /** @type {import('../iterateJsdoc.js').Integer} */
25
- let tagsIndex;
26
- const dupeTagInfo = propertyTags.find(([
27
- tgsIndex,
28
- tg,
29
- ], idx) => {
30
- tagsIndex = Number(tgsIndex);
31
-
32
- return tg.name === tag.name && idx !== index;
29
+ return propertyTagGroups.some((propertyTagGroup) => {
30
+ const propertyTags = propertyTagGroup.filter(([
31
+ , tag,
32
+ ]) => {
33
+ return tag.tag === targetTagName;
33
34
  });
34
- if (dupeTagInfo) {
35
- utils.reportJSDoc(`Duplicate @${targetTagName} "${tag.name}"`, dupeTagInfo[1], enableFixer ? () => {
36
- utils.removeTag(tagsIndex);
37
- } : null);
38
35
 
39
- return true;
40
- }
36
+ return propertyTags.some(([
37
+ , tag,
38
+ ], index) => {
39
+ /** @type {import('../iterateJsdoc.js').Integer} */
40
+ let tagsIndex;
41
+ const dupeTagInfo = propertyTags.find(([
42
+ tgsIndex,
43
+ tg,
44
+ ], idx) => {
45
+ tagsIndex = Number(tgsIndex);
46
+
47
+ return tg.name === tag.name && idx !== index;
48
+ });
49
+ if (dupeTagInfo) {
50
+ utils.reportJSDoc(`Duplicate @${targetTagName} "${tag.name}"`, dupeTagInfo[1], enableFixer ? () => {
51
+ utils.removeTag(tagsIndex);
52
+ } : null);
41
53
 
42
- return false;
54
+ return true;
55
+ }
56
+
57
+ return false;
58
+ });
43
59
  });
44
60
  };
45
61
 
@@ -111,7 +111,6 @@ export default {
111
111
 
112
112
  const decorator = getDecorator(
113
113
  /** @type {import('eslint').Rule.Node} */
114
- // @ts-expect-error Bug?
115
114
  (baseNode),
116
115
  );
117
116
  if (decorator) {
@@ -204,7 +203,6 @@ export default {
204
203
  reportingNonJsdoc = true;
205
204
 
206
205
  /** @type {AddComment} */
207
- // eslint-disable-next-line unicorn/consistent-function-scoping -- Avoid conflicts
208
206
  const addComment = (inlineCommentBlock, commentToAdd, indent, lines, fixer) => {
209
207
  const insertion = (
210
208
  inlineCommentBlock || enforceJsdocLineStyle === 'single' ?
@@ -36,6 +36,13 @@ const OPTIONS_SCHEMA = {
36
36
  additionalProperties: false,
37
37
  description: 'Has the following optional keys.\n',
38
38
  properties: {
39
+ checkAllFunctionExpressions: {
40
+ default: false,
41
+ description: `Normally, when \`FunctionExpression\` is checked, additional checks are
42
+ added to check the parent contexts where reporting is likely to be desired. If you really
43
+ want to check *all* function expressions, then set this to \`true\`.`,
44
+ type: 'boolean',
45
+ },
39
46
  checkConstructors: {
40
47
  default: true,
41
48
  description: `A value indicating whether \`constructor\`s should be checked. Defaults to
@@ -378,6 +385,7 @@ const getOption = (context, baseObject, option, key) => {
378
385
  * @param {import('eslint').Rule.RuleContext} context
379
386
  * @param {import('../iterateJsdoc.js').Settings} settings
380
387
  * @returns {{
388
+ * checkAllFunctionExpressions: boolean,
381
389
  * contexts: (string|{
382
390
  * context: string,
383
391
  * inlineCommentBlock: boolean,
@@ -396,6 +404,7 @@ const getOption = (context, baseObject, option, key) => {
396
404
  */
397
405
  const getOptions = (context, settings) => {
398
406
  const {
407
+ checkAllFunctionExpressions = false,
399
408
  contexts = settings.contexts || [],
400
409
  enableFixer = true,
401
410
  exemptEmptyConstructors = true,
@@ -408,6 +417,7 @@ const getOptions = (context, settings) => {
408
417
  } = context.options[0] || {};
409
418
 
410
419
  return {
420
+ checkAllFunctionExpressions,
411
421
  contexts,
412
422
  enableFixer,
413
423
  exemptEmptyConstructors,
@@ -503,7 +513,7 @@ const isFunctionWithOverload = (node) => {
503
513
  return false;
504
514
  }
505
515
 
506
- const functionName = node.id.name;
516
+ const functionName = node.id?.name;
507
517
 
508
518
  const idx = parent.body.indexOf(child);
509
519
  const prevSibling = parent.body[idx - 1];
@@ -536,6 +546,7 @@ export default {
536
546
  const opts = getOptions(context, settings);
537
547
 
538
548
  const {
549
+ checkAllFunctionExpressions,
539
550
  contexts,
540
551
  enableFixer,
541
552
  exemptEmptyConstructors,
@@ -670,7 +681,6 @@ export default {
670
681
 
671
682
  const decorator = getDecorator(
672
683
  /** @type {import('eslint').Rule.Node} */
673
- // @ts-expect-error Bug?
674
684
  (baseNode),
675
685
  );
676
686
  if (decorator) {
@@ -831,7 +841,7 @@ export default {
831
841
  return;
832
842
  }
833
843
 
834
- if (
844
+ if (checkAllFunctionExpressions ||
835
845
  [
836
846
  'AssignmentExpression', 'ExportDefaultDeclaration', 'VariableDeclarator',
837
847
  ].includes(node.parent.type) ||
package/src/rules.d.ts CHANGED
@@ -1639,6 +1639,12 @@ export interface Rules {
1639
1639
  | []
1640
1640
  | [
1641
1641
  {
1642
+ /**
1643
+ * Normally, when `FunctionExpression` is checked, additional checks are
1644
+ * added to check the parent contexts where reporting is likely to be desired. If you really
1645
+ * want to check *all* function expressions, then set this to `true`.
1646
+ */
1647
+ checkAllFunctionExpressions?: boolean;
1642
1648
  /**
1643
1649
  * A value indicating whether `constructor`s should be checked. Defaults to
1644
1650
  * `true`. When `true`, `exemptEmptyConstructors` may still avoid reporting when