Skip to content

Commit 8988510

Browse files
authored
Merge pull request #261 from brettz9/replaces-docs
feat: add settings `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` and apply to `require-param`, `require-description`, `require-example`, and `require-returns` for exempting all of these from errors in the case of the presence of `@override`, `@Augments`/`@extends`, or `@implements`, respectively. This commit also adds the following new behavior: with `require-description`, `inheritdoc` will avoid erring. This commit also causes the following non-breaking changes: With `require-example` and `require-returns`, `@override` may now err if the setting `overrideReplacesDocs` is set to false With `require-returns`, `@implements` may now err if the setting `implementsReplacesDocs` is set to false With `require-example`, `require-returns`, and `require-description`, `@Augments` or `@extends` may now avoid erring if the setting `augmentsExtendsReplacesDocs` is set to true Deprecating `settings.jsdoc.allowOverrideWithoutParam`, `settings.jsdoc.allowImplementsWithoutParam`, and `settings.jsdoc.allowAugmentsExtendsWithoutParam` in favor of the more tag-independent settings.
2 parents 6d6e1fc + 9cc49a2 commit 8988510

File tree

8 files changed

+173
-84
lines changed

8 files changed

+173
-84
lines changed

.README/README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,16 @@ tags in the rule `check-tag-names`. The format of the configuration is as follow
190190
}
191191
```
192192

193-
### Allow `@override` Without Accompanying `@param` Tags
193+
### `@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`
194194

195-
Use any of the following settings to override `require-param` and allow
196-
`@param` to be omitted when the specified tags are present on the JSDoc
197-
comment or the parent class comment. The default value for each is `false`.
195+
The following settings allows the element(s) they reference to be omitted
196+
on the JSDoc comment block of the function or that of its parent class
197+
for any of the "require" rules (i.e., `require-param`, `require-description`,
198+
`require-example`, or `require-returns`).
198199

199-
* `settings.jsdoc.allowOverrideWithoutParam` - Enables behavior with
200-
`@override` tag
201-
* `settings.jsdoc.allowImplementsWithoutParam` - Enables behavior with
202-
`@implements` tag
203-
* `settings.jsdoc.allowAugmentsExtendsWithoutParam` - Enables behavior with
204-
`@augments` tag or its synonym `@extends`
200+
* `settings.jsdoc.overrideReplacesDocs` (`@override`) - Defaults to `true`
201+
* `settings.jsdoc.augmentsExtendsReplacesDocs` (`@augments` or its alias `@extends`) - Defaults to `false`.
202+
* `settings.jsdoc.implementsReplacesDocs` (`@implements`) - Defaults to `false`
205203

206204
The format of the configuration is as follows:
207205

@@ -210,14 +208,19 @@ The format of the configuration is as follows:
210208
"rules": {},
211209
"settings": {
212210
"jsdoc": {
213-
"allowOverrideWithoutParam": true,
214-
"allowImplementsWithoutParam": true,
215-
"allowAugmentsExtendsWithoutParam": true
211+
"overrideReplacesDocs": true,
212+
"augmentsExtendsReplacesDocs": true,
213+
"implementsReplacesDocs": true
216214
}
217215
}
218216
}
219217
```
220218

219+
`settings.jsdoc.allowOverrideWithoutParam`,
220+
`settings.jsdoc.allowImplementsWithoutParam`, and
221+
`settings.jsdoc.allowAugmentsExtendsWithoutParam` performed a similar function
222+
but restricted to `@param`. These settings are now deprecated.
223+
221224
### Settings to Configure `check-types` and `no-undefined-types`
222225

223226
- `settings.jsdoc.preferredTypes` An option map to indicate preferred

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ JSDoc linting rules for ESLint.
1717
* [Exempting empty functions from `require-jsdoc`](#eslint-plugin-jsdoc-settings-exempting-empty-functions-from-require-jsdoc)
1818
* [Alias Preference](#eslint-plugin-jsdoc-settings-alias-preference)
1919
* [Additional Tag Names](#eslint-plugin-jsdoc-settings-additional-tag-names)
20-
* [Allow `@override` Without Accompanying `@param` Tags](#eslint-plugin-jsdoc-settings-allow-override-without-accompanying-param-tags)
20+
* [`@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`](#eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns)
2121
* [Settings to Configure `check-types` and `no-undefined-types`](#eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types)
2222
* [Settings to Configure `valid-types`](#eslint-plugin-jsdoc-settings-settings-to-configure-valid-types)
2323
* [Settings to Configure `require-returns`](#eslint-plugin-jsdoc-settings-settings-to-configure-require-returns)
@@ -241,19 +241,17 @@ tags in the rule `check-tag-names`. The format of the configuration is as follow
241241
}
242242
```
243243

244-
<a name="eslint-plugin-jsdoc-settings-allow-override-without-accompanying-param-tags"></a>
245-
### Allow <code>@override</code> Without Accompanying <code>@param</code> Tags
244+
<a name="eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns"></a>
245+
### <code>@override</code>/<code>@augments</code>/<code>@extends</code>/<code>@implements</code> Without Accompanying <code>@param</code>/<code>@description</code>/<code>@example</code>/<code>@returns</code>
246246

247-
Use any of the following settings to override `require-param` and allow
248-
`@param` to be omitted when the specified tags are present on the JSDoc
249-
comment or the parent class comment. The default value for each is `false`.
247+
The following settings allows the element(s) they reference to be omitted
248+
on the JSDoc comment block of the function or that of its parent class
249+
for any of the "require" rules (i.e., `require-param`, `require-description`,
250+
`require-example`, or `require-returns`).
250251

251-
* `settings.jsdoc.allowOverrideWithoutParam` - Enables behavior with
252-
`@override` tag
253-
* `settings.jsdoc.allowImplementsWithoutParam` - Enables behavior with
254-
`@implements` tag
255-
* `settings.jsdoc.allowAugmentsExtendsWithoutParam` - Enables behavior with
256-
`@augments` tag or its synonym `@extends`
252+
* `settings.jsdoc.overrideReplacesDocs` (`@override`) - Defaults to `true`
253+
* `settings.jsdoc.augmentsExtendsReplacesDocs` (`@augments` or its alias `@extends`) - Defaults to `false`.
254+
* `settings.jsdoc.implementsReplacesDocs` (`@implements`) - Defaults to `false`
257255

258256
The format of the configuration is as follows:
259257

@@ -262,14 +260,19 @@ The format of the configuration is as follows:
262260
"rules": {},
263261
"settings": {
264262
"jsdoc": {
265-
"allowOverrideWithoutParam": true,
266-
"allowImplementsWithoutParam": true,
267-
"allowAugmentsExtendsWithoutParam": true
263+
"overrideReplacesDocs": true,
264+
"augmentsExtendsReplacesDocs": true,
265+
"implementsReplacesDocs": true
268266
}
269267
}
270268
}
271269
```
272270

271+
`settings.jsdoc.allowOverrideWithoutParam`,
272+
`settings.jsdoc.allowImplementsWithoutParam`, and
273+
`settings.jsdoc.allowAugmentsExtendsWithoutParam` performed a similar function
274+
but restricted to `@param`. These settings are now deprecated.
275+
273276
<a name="eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types"></a>
274277
### Settings to Configure <code>check-types</code> and <code>no-undefined-types</code>
275278

src/iterateJsdoc.js

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const curryUtils = (
3838
allowEmptyNamepaths,
3939
reportUnusedDisableDirectives,
4040
noDefaultExampleRules,
41+
overrideReplacesDocs,
42+
implementsReplacesDocs,
43+
augmentsExtendsReplacesDocs,
4144
allowOverrideWithoutParam,
4245
allowImplementsWithoutParam,
4346
allowAugmentsExtendsWithoutParam,
@@ -130,16 +133,46 @@ const curryUtils = (
130133
return captionRequired;
131134
};
132135

133-
utils.isOverrideAllowedWithoutParam = () => {
134-
return allowOverrideWithoutParam;
135-
};
136+
// These settings are deprecated and may be removed in the future along with this method.
137+
utils.avoidDocsParamOnly = () => {
138+
// These three checks are all for deprecated settings and may be removed in the future
139+
140+
// When settings.jsdoc.allowOverrideWithoutParam is true, override implies that all documentation is inherited.
141+
if ((utils.hasTag('override') || utils.classHasTag('override')) && allowOverrideWithoutParam !== false) {
142+
return true;
143+
}
136144

137-
utils.isImplementsAllowedWithoutParam = () => {
138-
return allowImplementsWithoutParam;
145+
// When settings.jsdoc.allowImplementsWithoutParam is true, implements implies that all documentation is inherited.
146+
// See https://github.com/gajus/eslint-plugin-jsdoc/issues/100
147+
if ((utils.hasTag('implements') || utils.classHasTag('implements')) && allowImplementsWithoutParam !== false) {
148+
return true;
149+
}
150+
151+
// When settings.jsdoc.allowAugmentsExtendsWithoutParam is true, augments or extends implies that all documentation is inherited.
152+
if ((utils.hasTag('augments') || utils.hasTag('extends') ||
153+
utils.classHasTag('augments') || utils.classHasTag('extends')) && allowAugmentsExtendsWithoutParam) {
154+
return true;
155+
}
156+
157+
return false;
139158
};
140159

141-
utils.isAugmentsExtendsAllowedWithoutParam = () => {
142-
return allowAugmentsExtendsWithoutParam;
160+
utils.avoidDocs = (param) => {
161+
return param && utils.avoidDocsParamOnly() ||
162+
163+
// inheritdoc implies that all documentation is inherited; see http://usejsdoc.org/tags-inheritdoc.html
164+
utils.hasTag('inheritdoc') ||
165+
166+
// After deprecation, the `param` parameter can be removed, but for now,
167+
// don't default for `param` as it may have its own explicit settings to the contrary
168+
(param && overrideReplacesDocs || !param && overrideReplacesDocs !== false) &&
169+
(utils.hasTag('override') || utils.classHasTag('override')) ||
170+
(param && implementsReplacesDocs || !param && implementsReplacesDocs !== false) &&
171+
(utils.hasTag('implements') || utils.classHasTag('implements')) ||
172+
augmentsExtendsReplacesDocs &&
173+
(utils.hasATag(['augments', 'extends']) ||
174+
utils.classHasTag('augments') ||
175+
utils.classHasTag('extends'));
143176
};
144177

145178
utils.isNamepathDefiningTag = (tagName) => {
@@ -263,10 +296,15 @@ export default (iterator, opts = {}) => {
263296
const captionRequired = Boolean(_.get(context, 'settings.jsdoc.captionRequired'));
264297
const noDefaultExampleRules = Boolean(_.get(context, 'settings.jsdoc.noDefaultExampleRules'));
265298

266-
// `require-param` only
267-
const allowOverrideWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowOverrideWithoutParam'));
268-
const allowImplementsWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowImplementsWithoutParam'));
269-
const allowAugmentsExtendsWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam'));
299+
// `require-param`, `require-description`, `require-example`, `require-returns`
300+
const overrideReplacesDocs = _.get(context, 'settings.jsdoc.overrideReplacesDocs');
301+
const implementsReplacesDocs = _.get(context, 'settings.jsdoc.implementsReplacesDocs');
302+
const augmentsExtendsReplacesDocs = _.get(context, 'settings.jsdoc.augmentsExtendsReplacesDocs');
303+
304+
// `require-param` only (deprecated)
305+
const allowOverrideWithoutParam = _.get(context, 'settings.jsdoc.allowOverrideWithoutParam');
306+
const allowImplementsWithoutParam = _.get(context, 'settings.jsdoc.allowImplementsWithoutParam');
307+
const allowAugmentsExtendsWithoutParam = _.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam');
270308

271309
// `valid-types` only
272310
const allowEmptyNamepaths = _.get(context, 'settings.jsdoc.allowEmptyNamepaths') !== false;
@@ -342,6 +380,9 @@ export default (iterator, opts = {}) => {
342380
allowEmptyNamepaths,
343381
reportUnusedDisableDirectives,
344382
noDefaultExampleRules,
383+
overrideReplacesDocs,
384+
implementsReplacesDocs,
385+
augmentsExtendsReplacesDocs,
345386
allowOverrideWithoutParam,
346387
allowImplementsWithoutParam,
347388
allowAugmentsExtendsWithoutParam,

src/rules/requireDescription.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export default iterateJsdoc(({
66
report,
77
utils
88
}) => {
9+
if (utils.avoidDocs()) {
10+
return;
11+
}
12+
913
const targetTagName = utils.getPreferredTagName('description');
1014

1115
const functionExamples = _.filter(jsdoc.tags, {

src/rules/requireExample.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ export default iterateJsdoc(({
66
report,
77
utils
88
}) => {
9+
if (utils.avoidDocs()) {
10+
return;
11+
}
12+
913
const targetTagName = 'example';
1014

1115
const functionExamples = _.filter(jsdoc.tags, {
1216
tag: targetTagName
1317
});
1418

15-
if (utils.hasATag([
16-
'inheritdoc',
17-
'override'
18-
])) {
19-
return;
20-
}
21-
2219
if (utils.avoidExampleOnConstructors() && (
2320
utils.hasATag([
2421
'class',

src/rules/requireParam.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,7 @@ export default iterateJsdoc(({
88
const functionParameterNames = utils.getFunctionParameterNames();
99
const jsdocParameterNames = utils.getJsdocParameterNames();
1010

11-
// inheritdoc implies that all documentation is inherited; see http://usejsdoc.org/tags-inheritdoc.html
12-
if (utils.hasTag('inheritdoc')) {
13-
return;
14-
}
15-
16-
// When settings.jsdoc.allowOverrideWithoutParam is true, override implies that all documentation is inherited.
17-
// See https://github.com/gajus/eslint-plugin-jsdoc/issues/73
18-
if ((utils.hasTag('override') || utils.classHasTag('override')) && utils.isOverrideAllowedWithoutParam()) {
19-
return;
20-
}
21-
22-
// When settings.jsdoc.allowImplementsWithoutParam is true, implements implies that all documentation is inherited.
23-
// See https://github.com/gajus/eslint-plugin-jsdoc/issues/100
24-
if ((utils.hasTag('implements') || utils.classHasTag('implements')) && utils.isImplementsAllowedWithoutParam()) {
25-
return;
26-
}
27-
28-
// When settings.jsdoc.allowAugmentsExtendsWithoutParam is true, augments or extends implies that all documentation is inherited.
29-
// See https://github.com/gajus/eslint-plugin-jsdoc/issues/100
30-
if ((utils.hasTag('augments') || utils.hasTag('extends') ||
31-
utils.classHasTag('augments') || utils.classHasTag('extends')) && utils.isAugmentsExtendsAllowedWithoutParam()) {
11+
if (utils.avoidDocs('param')) {
3212
return;
3313
}
3414

src/rules/requireReturns.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ const canSkip = (utils) => {
1616
// inheritdoc implies that all documentation is inherited
1717
// see http://usejsdoc.org/tags-inheritdoc.html
1818
//
19-
// As we do not know the parent method, we cannot perform any checks.
20-
'inheritdoc',
21-
'override',
22-
23-
// Different Tag similar story. Abstract methods are by definition incomplete,
19+
// Abstract methods are by definition incomplete,
2420
// so it is not an error if it declares a return value but does not implement it.
2521
'abstract',
2622
'virtual',
@@ -31,19 +27,14 @@ const canSkip = (utils) => {
3127
'constructor',
3228

3329
// This seems to imply a class as well
34-
'interface',
35-
36-
// While we may, in a future rule, err in the case of (regular) functions
37-
// using @implements (see https://github.com/gajus/eslint-plugin-jsdoc/issues/201 ),
38-
// this should not error for those using the tag to indicate implementation of
39-
// a particular function signature
40-
'implements'
30+
'interface'
4131
]) ||
4232
utils.isConstructor() ||
4333

4434
// Though ESLint avoided getters: https://github.com/eslint/eslint/blob/master/lib/rules/valid-jsdoc.js#L435
4535
// ... getters seem that they should, unlike setters, always return:
46-
utils.isSetter();
36+
utils.isSetter() ||
37+
utils.avoidDocs();
4738
};
4839

4940
export default iterateJsdoc(({

0 commit comments

Comments
 (0)