Skip to content

Commit 6413e7d

Browse files
rsimhagajus
authored andcommitted
feat: add an allowOverrideWithoutParam setting for jsdoc/require-param (#74)
1 parent 94464cd commit 6413e7d

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ JSDoc linting rules for ESLint.
1414
* [Settings](#eslint-plugin-jsdoc-settings)
1515
* [Alias Preference](#eslint-plugin-jsdoc-settings-alias-preference)
1616
* [Additional Tag Names](#eslint-plugin-jsdoc-settings-additional-tag-names)
17+
* [Allow `@override` Without Accompanying `@param` Tags](#eslint-plugin-jsdoc-settings-allow-override-without-param)
1718
* [Rules](#eslint-plugin-jsdoc-rules)
1819
* [`check-param-names`](#eslint-plugin-jsdoc-rules-check-param-names)
1920
* [`check-tag-names`](#eslint-plugin-jsdoc-rules-check-tag-names)
@@ -148,6 +149,22 @@ Use `settings.jsdoc.additionalTagNames` to configure additional, allowed JSDoc t
148149
}
149150
```
150151

152+
<a name="eslint-plugin-jsdoc-settings-allow-override-without-param"></a>
153+
### Allow `@override` Without Accompanying `@param` Tags
154+
155+
Use `settings.jsdoc.allowOverrideWithoutParam` to indicate whether the `@override` tag can be used without accompanying `@param` tag(s). The default value is `false`. The format of the configuration is as follows:
156+
157+
```json
158+
{
159+
"rules": {},
160+
"settings": {
161+
"jsdoc": {
162+
"allowOverrideWithoutParam": true
163+
}
164+
}
165+
}
166+
```
167+
151168
<a name="eslint-plugin-jsdoc-rules"></a>
152169
## Rules
153170

@@ -998,6 +1015,14 @@ function quux (foo, bar) {
9981015

9991016
}
10001017
// Message: Missing JSDoc @param "bar" declaration.
1018+
1019+
/**
1020+
* @override
1021+
*/
1022+
function quux (foo) {
1023+
1024+
}
1025+
// Message: Missing JSDoc @arg "foo" declaration.
10011026
```
10021027

10031028
The following patterns are not considered problems:
@@ -1023,6 +1048,22 @@ function quux (foo) {
10231048
function quux (foo) {
10241049

10251050
}
1051+
1052+
/**
1053+
* @override
1054+
* @param foo
1055+
*/
1056+
function quux (foo) {
1057+
1058+
}
1059+
1060+
/**
1061+
* @override
1062+
*/
1063+
function quux (foo) {
1064+
1065+
}
1066+
// Settings: { "allowOverrideWithoutParam": true }
10261067
```
10271068

10281069

src/iterateJsdoc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash';
22
import commentParser from 'comment-parser';
33
import jsdocUtils from './jsdocUtils';
44

5-
const curryUtils = (functionNode, jsdoc, tagNamePreference, additionalTagNames) => {
5+
const curryUtils = (functionNode, jsdoc, tagNamePreference, additionalTagNames, allowOverrideWithoutParam) => {
66
const utils = {};
77

88
utils.getFunctionParameterNames = () => {
@@ -29,6 +29,10 @@ const curryUtils = (functionNode, jsdoc, tagNamePreference, additionalTagNames)
2929
return jsdocUtils.hasTag(jsdoc, name);
3030
};
3131

32+
utils.isOverrideAllowedWithoutParam = () => {
33+
return allowOverrideWithoutParam;
34+
};
35+
3236
return utils;
3337
};
3438

@@ -58,6 +62,7 @@ export default (iterator) => {
5862
const sourceCode = context.getSourceCode();
5963
const tagNamePreference = _.get(context, 'settings.jsdoc.tagNamePreference') || {};
6064
const additionalTagNames = _.get(context, 'settings.jsdoc.additionalTagNames') || {};
65+
const allowOverrideWithoutParam = Boolean(_.get(context, 'settings.jsdoc.allowOverrideWithoutParam'));
6166

6267
const checkJsdoc = (functionNode) => {
6368
const jsdocNode = sourceCode.getJSDocComment(functionNode);
@@ -82,7 +87,7 @@ export default (iterator) => {
8287
}
8388
};
8489

85-
const utils = curryUtils(functionNode, jsdoc, tagNamePreference, additionalTagNames);
90+
const utils = curryUtils(functionNode, jsdoc, tagNamePreference, additionalTagNames, allowOverrideWithoutParam);
8691

8792
iterator({
8893
context,

src/rules/requireParam.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ export default iterateJsdoc(({
1313
return;
1414
}
1515

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.isOverrideAllowedWithoutParam()) {
19+
return;
20+
}
21+
1622
_.some(functionParameterNames, (functionParameterName, index) => {
1723
const jsdocParameterName = jsdocParameterNames[index];
1824

test/rules/assertions/requireParam.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ export default {
5353
message: 'Missing JSDoc @param "bar" declaration.'
5454
}
5555
]
56+
},
57+
{
58+
code: `
59+
/**
60+
* @override
61+
*/
62+
function quux (foo) {
63+
64+
}
65+
`,
66+
errors: [
67+
{
68+
message: 'Missing JSDoc @param "foo" declaration.'
69+
}
70+
]
5671
}
5772
],
5873
valid: [
@@ -92,6 +107,32 @@ export default {
92107
}
93108
}
94109
}
110+
},
111+
{
112+
code: `
113+
/**
114+
* @override
115+
* @param foo
116+
*/
117+
function quux (foo) {
118+
119+
}
120+
`
121+
},
122+
{
123+
code: `
124+
/**
125+
* @override
126+
*/
127+
function quux (foo) {
128+
129+
}
130+
`,
131+
settings: {
132+
jsdoc: {
133+
allowOverrideWithoutParam: true
134+
}
135+
}
95136
}
96137
]
97138
};

0 commit comments

Comments
 (0)