Skip to content

Commit a402330

Browse files
committed
feat(require-description, require-example, require-param, require-returns): cause exemptedBy to overwrite inheritdoc exempting; closes #510
BREAKING CHANGE: While still defaulting to having `inheritdoc` exempt rules, for the impacted rules, if one has defined an `exemptedBy` options array one must now explicitly add back `"inheritdoc"` to get the exemption for that tag as well. This change allows users to omit `inheritdoc` from the array so as to cause its presence not to trigger exemption of the rule.
1 parent 3aaba73 commit a402330

File tree

7 files changed

+62
-13
lines changed

7 files changed

+62
-13
lines changed

.README/rules/require-description.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ An options object may have any of the following properties:
1818
you want the rule to apply to any jsdoc block throughout your files.
1919
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
2020
document block avoids the need for a `@description`. Defaults to an
21-
empty array.
21+
array with `inheritdoc`. If you set this array, it will overwrite the
22+
default, so be sure to add back `inheritdoc` if you wish its presence
23+
to cause exemption of the rule.
2224
- `descriptionStyle` - Whether to accept implicit descriptions (`"body"`) or
2325
`@description` tags (`"tag"`) as satisfying the rule. Set to `"any"` to
2426
accept either style. Defaults to `"body"`.

.README/rules/require-example.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ This rule has an object option.
1212
##### `exemptedBy`
1313

1414
Array of tags (e.g., `['type']`) whose presence on the document
15-
block avoids the need for an `@example`. Defaults to an empty array.
15+
block avoids the need for an `@example`. Defaults to an array with
16+
`inheritdoc`. If you set this array, it will overwrite the default,
17+
so be sure to add back `inheritdoc` if you wish its presence to cause
18+
exemption of the rule.
1619

1720
##### `avoidExampleOnConstructors`
1821

.README/rules/require-param.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ An options object accepts two optional properties:
99
##### `exemptedBy`
1010

1111
Array of tags (e.g., `['type']`) whose presence on the document block
12-
avoids the need for a `@param`. Defaults to an empty array.
12+
avoids the need for a `@param`. Defaults to an array with
13+
`inheritdoc`. If you set this array, it will overwrite the default,
14+
so be sure to add back `inheritdoc` if you wish its presence to cause
15+
exemption of the rule.
1316

1417
##### `contexts`
1518

.README/rules/require-returns.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Will also report if multiple `@returns` tags are present.
99
- `checkGetters` - Boolean to determine whether getter methods should
1010
be checked for `@returns` tags. Defaults to `true`.
1111
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
12-
block avoids the need for a `@returns`. Defaults to an empty array.
12+
block avoids the need for a `@returns`. Defaults to an array with
13+
`inheritdoc`. If you set this array, it will overwrite the default,
14+
so be sure to add back `inheritdoc` if you wish its presence to cause
15+
exemption of the rule.
1316
- `forceRequireReturn` - Set to `true` to always insist on
1417
`@returns` documentation regardless of implicit or explicit `return`'s
1518
in the function. May be desired to flag that a project is aware of an

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6421,7 +6421,9 @@ An options object may have any of the following properties:
64216421
you want the rule to apply to any jsdoc block throughout your files.
64226422
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
64236423
document block avoids the need for a `@description`. Defaults to an
6424-
empty array.
6424+
array with `inheritdoc`. If you set this array, it will overwrite the
6425+
default, so be sure to add back `inheritdoc` if you wish its presence
6426+
to cause exemption of the rule.
64256427
- `descriptionStyle` - Whether to accept implicit descriptions (`"body"`) or
64266428
`@description` tags (`"tag"`) as satisfying the rule. Set to `"any"` to
64276429
accept either style. Defaults to `"body"`.
@@ -6715,7 +6717,10 @@ This rule has an object option.
67156717
##### <code>exemptedBy</code>
67166718
67176719
Array of tags (e.g., `['type']`) whose presence on the document
6718-
block avoids the need for an `@example`. Defaults to an empty array.
6720+
block avoids the need for an `@example`. Defaults to an array with
6721+
`inheritdoc`. If you set this array, it will overwrite the default,
6722+
so be sure to add back `inheritdoc` if you wish its presence to cause
6723+
exemption of the rule.
67196724
67206725
<a name="eslint-plugin-jsdoc-rules-require-example-options-16-avoidexampleonconstructors"></a>
67216726
##### <code>avoidExampleOnConstructors</code>
@@ -8769,7 +8774,10 @@ An options object accepts two optional properties:
87698774
##### <code>exemptedBy</code>
87708775

87718776
Array of tags (e.g., `['type']`) whose presence on the document block
8772-
avoids the need for a `@param`. Defaults to an empty array.
8777+
avoids the need for a `@param`. Defaults to an array with
8778+
`inheritdoc`. If you set this array, it will overwrite the default,
8779+
so be sure to add back `inheritdoc` if you wish its presence to cause
8780+
exemption of the rule.
87738781

87748782
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-contexts-7"></a>
87758783
##### <code>contexts</code>
@@ -9000,6 +9008,15 @@ function quux (foo) {
90009008
// Options: [{"exemptedBy":["notPresent"]}]
90019009
// Message: Missing JSDoc @param "foo" declaration.
90029010

9011+
/**
9012+
* @inheritdoc
9013+
*/
9014+
function quux (foo) {
9015+
9016+
}
9017+
// Options: [{"exemptedBy":[]}]
9018+
// Message: Missing JSDoc @param "foo" declaration.
9019+
90039020
/**
90049021
* Assign the project to a list of employees.
90059022
* @param {object[]} employees - The employees who are responsible for the project.
@@ -10328,7 +10345,10 @@ Will also report if multiple `@returns` tags are present.
1032810345
- `checkGetters` - Boolean to determine whether getter methods should
1032910346
be checked for `@returns` tags. Defaults to `true`.
1033010347
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
10331-
block avoids the need for a `@returns`. Defaults to an empty array.
10348+
block avoids the need for a `@returns`. Defaults to an array with
10349+
`inheritdoc`. If you set this array, it will overwrite the default,
10350+
so be sure to add back `inheritdoc` if you wish its presence to cause
10351+
exemption of the rule.
1033210352
- `forceRequireReturn` - Set to `true` to always insist on
1033310353
`@returns` documentation regardless of implicit or explicit `return`'s
1033410354
in the function. May be desired to flag that a project is aware of an

src/iterateJsdoc.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,15 @@ const getUtils = (
238238
implementsReplacesDocs !== false &&
239239
(utils.hasTag('implements') || utils.classHasTag('implements')) ||
240240

241-
// inheritdoc implies that all documentation is inherited; see https://jsdoc.app/tags-inheritdoc.html
242-
utils.hasTag('inheritdoc') ||
243-
244241
augmentsExtendsReplacesDocs &&
245242
(utils.hasATag(['augments', 'extends']) ||
246243
utils.classHasTag('augments') ||
247244
utils.classHasTag('extends'))) {
248245
return true;
249246
}
250247

251-
const exemptedBy = _.get(context, 'options[0].exemptedBy');
252-
if (exemptedBy && exemptedBy.length && utils.getPresentTags(exemptedBy).length) {
248+
const exemptedBy = _.get(context, 'options[0].exemptedBy', ['inheritdoc']);
249+
if (exemptedBy.length && utils.getPresentTags(exemptedBy).length) {
253250
return true;
254251
}
255252

test/rules/assertions/requireParam.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,27 @@ export default {
520520
},
521521
],
522522
},
523+
{
524+
code: `
525+
/**
526+
* @inheritdoc
527+
*/
528+
function quux (foo) {
529+
530+
}
531+
`,
532+
errors: [
533+
{
534+
line: 2,
535+
message: 'Missing JSDoc @param "foo" declaration.',
536+
},
537+
],
538+
options: [
539+
{
540+
exemptedBy: [],
541+
},
542+
],
543+
},
523544
{
524545
code: `
525546
/**

0 commit comments

Comments
 (0)