eslint-plugin-jsdoc 65.3.1 → 65.3.3

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.
package/dist/rules.d.ts CHANGED
@@ -334,16 +334,23 @@ export interface Rules {
334
334
  * class
335
335
  * enum
336
336
  * implements
337
- * private
338
337
  * property
339
- * protected
340
- * public
341
338
  * readonly
342
339
  * this
343
340
  * type
344
341
  * typedef
345
342
  * ```
346
343
  *
344
+ * These tags are unnecessary on class members (where TypeScript has access
345
+ * modifiers), but are allowed elsewhere (e.g., the `@public` release tag of
346
+ * TSDoc/API Extractor on an exported function):
347
+ *
348
+ * ```
349
+ * private
350
+ * protected
351
+ * public
352
+ * ```
353
+ *
347
354
  * These tags are unnecessary except when inside a TypeScript `declare` context:
348
355
  *
349
356
  * ```
package/package.json CHANGED
@@ -163,5 +163,5 @@
163
163
  "test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
164
164
  "test-index": "pnpm run test-no-cov test/rules/index.js"
165
165
  },
166
- "version": "65.3.1"
166
+ "version": "65.3.3"
167
167
  }
@@ -29,6 +29,20 @@ const typedTagsNeedingName = new Set([
29
29
  'template',
30
30
  ]);
31
31
 
32
+ const accessTags = new Set([
33
+ 'private',
34
+ 'protected',
35
+ 'public',
36
+ ]);
37
+
38
+ /**
39
+ * @param {import('eslint').Rule.Node|null} node
40
+ * @returns {boolean}
41
+ */
42
+ const isClassMember = (node) => {
43
+ return node?.parent?.type === 'ClassBody';
44
+ };
45
+
32
46
  const typedTagsUnnecessaryOutsideDeclare = new Set([
33
47
  'abstract',
34
48
  'access',
@@ -201,7 +215,13 @@ export default iterateJsdoc(({
201
215
  * @returns {boolean}
202
216
  */
203
217
  const checkTagForTypedValidity = (jsdocTag, tagIndex) => {
204
- if (typedTagsAlwaysUnnecessary.has(jsdocTag.tag)) {
218
+ if (
219
+ typedTagsAlwaysUnnecessary.has(jsdocTag.tag) &&
220
+ // TypeScript only has syntax for these on class members; elsewhere they
221
+ // are not redundant (e.g., TSDoc/API Extractor release tag `@public`,
222
+ // TypeDoc's `@private`/`@protected` visibility, Knip's `@public`)
223
+ (!accessTags.has(jsdocTag.tag) || isClassMember(node))
224
+ ) {
205
225
  reportWithTagRemovalFixer(
206
226
  `'@${jsdocTag.tag}' is redundant when using a type system.`,
207
227
  jsdocTag,
@@ -361,16 +381,23 @@ callback
361
381
  class
362
382
  enum
363
383
  implements
364
- private
365
384
  property
366
- protected
367
- public
368
385
  readonly
369
386
  this
370
387
  type
371
388
  typedef
372
389
  \`\`\`
373
390
 
391
+ These tags are unnecessary on class members (where TypeScript has access
392
+ modifiers), but are allowed elsewhere (e.g., the \`@public\` release tag of
393
+ TSDoc/API Extractor on an exported function):
394
+
395
+ \`\`\`
396
+ private
397
+ protected
398
+ public
399
+ \`\`\`
400
+
374
401
  These tags are unnecessary except when inside a TypeScript \`declare\` context:
375
402
 
376
403
  \`\`\`
@@ -1,7 +1,20 @@
1
1
  import iterateJsdoc from '../iterateJsdoc.js';
2
2
 
3
+ /**
4
+ * @param {import('eslint').Rule.Node|null} node
5
+ * @returns {boolean}
6
+ */
7
+ const isAccessor = (node) => {
8
+ const methodNode = node?.type === 'FunctionExpression' ? node.parent : node;
9
+
10
+ return [
11
+ 'get', 'set',
12
+ ].includes(/** @type {{kind?: string}} */ (methodNode)?.kind ?? '');
13
+ };
14
+
3
15
  export default iterateJsdoc(({
4
16
  context,
17
+ node,
5
18
  utils,
6
19
  }) => {
7
20
  const {
@@ -26,6 +39,12 @@ export default iterateJsdoc(({
26
39
  }
27
40
  }
28
41
 
42
+ // A getter or setter has no initializer which a `@default` could repeat;
43
+ // its `@default` documents the default value of the property
44
+ if (isAccessor(node)) {
45
+ return;
46
+ }
47
+
29
48
  const defaultTags = utils.getPresentTags([
30
49
  'default', 'defaultvalue',
31
50
  ]);
package/src/rules.d.ts CHANGED
@@ -334,16 +334,23 @@ export interface Rules {
334
334
  * class
335
335
  * enum
336
336
  * implements
337
- * private
338
337
  * property
339
- * protected
340
- * public
341
338
  * readonly
342
339
  * this
343
340
  * type
344
341
  * typedef
345
342
  * ```
346
343
  *
344
+ * These tags are unnecessary on class members (where TypeScript has access
345
+ * modifiers), but are allowed elsewhere (e.g., the `@public` release tag of
346
+ * TSDoc/API Extractor on an exported function):
347
+ *
348
+ * ```
349
+ * private
350
+ * protected
351
+ * public
352
+ * ```
353
+ *
347
354
  * These tags are unnecessary except when inside a TypeScript `declare` context:
348
355
  *
349
356
  * ```