Skip to content

Commit b653d3f

Browse files
committed
- Enhancement: Rule to prevent types on @param/@returns
- Docs: Clarify how sentence above preceding list continues
1 parent 832399f commit b653d3f

File tree

7 files changed

+82
-1
lines changed

7 files changed

+82
-1
lines changed

.README/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Finally, enable all of the rules that you would like to use.
8585
"jsdoc/implements-on-classes": 1,
8686
"jsdoc/match-description": 1,
8787
"jsdoc/newline-after-description": 1,
88+
"jsdoc/no-types": 1,
8889
"jsdoc/no-undefined-types": 1,
8990
"jsdoc/require-description": 1,
9091
"jsdoc/require-description-complete-sentence": 1,
@@ -316,6 +317,7 @@ Finally, the following rule pertains to inline disable directives:
316317
{"gitdown": "include", "file": "./rules/implements-on-classes.md"}
317318
{"gitdown": "include", "file": "./rules/match-description.md"}
318319
{"gitdown": "include", "file": "./rules/newline-after-description.md"}
320+
{"gitdown": "include", "file": "./rules/no-types.md"}
319321
{"gitdown": "include", "file": "./rules/no-undefined-types.md"}
320322
{"gitdown": "include", "file": "./rules/require-description-complete-sentence.md"}
321323
{"gitdown": "include", "file": "./rules/require-description.md"}

.README/rules/no-types.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### `no-types`
2+
3+
This rule reports types being used on `@param` or `@returns`.
4+
5+
The rule is intended to prevent the indication of types on tags where
6+
the type information would be redundant with TypeScript.
7+
8+
|||
9+
|---|---|
10+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
11+
|Tags|`param`, `returns`|
12+
|Aliases|`arg`, `argument`, `return`|
13+
14+
<!-- assertions noTypes -->

.README/rules/valid-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
1010
1. Name(path)-pointing tags (which may have value without namepath): `@listens`, `@fires`, `@emits`
1111
1. Name(path)-pointing tags (multiple names in one): `@borrows`
1212

13-
The following apply to the above sets:
13+
...with the following applying to the above sets:
1414

1515
- Expect tags in set 1-4 to have a valid namepath if present
1616
- Prevent sets 3-4 from being empty by setting `allowEmptyNamepaths` to `false` as these tags might have some indicative value without a path (but sets 1-2 will always fail if empty)

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import checkTypes from './rules/checkTypes';
99
import implementsOnClasses from './rules/implementsOnClasses';
1010
import matchDescription from './rules/matchDescription';
1111
import newlineAfterDescription from './rules/newlineAfterDescription';
12+
import noTypes from './rules/noTypes';
1213
import noUndefinedTypes from './rules/noUndefinedTypes';
1314
import requireDescriptionCompleteSentence from './rules/requireDescriptionCompleteSentence';
1415
import requireDescription from './rules/requireDescription';
@@ -39,6 +40,7 @@ export default {
3940
'jsdoc/implements-on-classes': 'warn',
4041
'jsdoc/match-description': 'off',
4142
'jsdoc/newline-after-description': 'warn',
43+
'jsdoc/no-types': 'off',
4244
'jsdoc/no-undefined-types': 'warn',
4345
'jsdoc/require-description': 'off',
4446
'jsdoc/require-description-complete-sentence': 'off',
@@ -68,6 +70,7 @@ export default {
6870
'implements-on-classes': implementsOnClasses,
6971
'match-description': matchDescription,
7072
'newline-after-description': newlineAfterDescription,
73+
'no-types': noTypes,
7174
'no-undefined-types': noUndefinedTypes,
7275
'require-description': requireDescription,
7376
'require-description-complete-sentence': requireDescriptionCompleteSentence,

src/rules/noTypes.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import iterateJsdoc from '../iterateJsdoc';
2+
3+
export default iterateJsdoc(({
4+
jsdoc,
5+
report
6+
}) => {
7+
const tags = jsdoc.tags.filter((tag) => {
8+
return ['param', 'arg', 'argument', 'returns', 'return'].includes(tag.tag);
9+
});
10+
tags.forEach((tag) => {
11+
if (tag.type) {
12+
report(`Types are not permitted on @${tag.tag}.`, null, tag);
13+
}
14+
});
15+
});

test/rules/assertions/noTypes.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export default {
2+
invalid: [
3+
{
4+
code: `
5+
/**
6+
* @param {number} foo
7+
*/
8+
function quux (foo) {
9+
10+
}
11+
`,
12+
errors: [
13+
{
14+
message: 'Types are not permitted on @param.'
15+
}
16+
]
17+
},
18+
{
19+
code: `
20+
/**
21+
* @returns {number}
22+
*/
23+
function quux () {
24+
25+
}
26+
`,
27+
errors: [
28+
{
29+
message: 'Types are not permitted on @returns.'
30+
}
31+
]
32+
}
33+
],
34+
valid: [
35+
{
36+
code: `
37+
/**
38+
* @param foo
39+
*/
40+
function quux (foo) {
41+
42+
}
43+
`
44+
}
45+
]
46+
};

test/rules/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ruleTester = new RuleTester();
1717
'implements-on-classes',
1818
'match-description',
1919
'newline-after-description',
20+
'no-types',
2021
'no-undefined-types',
2122
'require-description',
2223
'require-description-complete-sentence',

0 commit comments

Comments
 (0)