Skip to content

Commit e791ec3

Browse files
brettz9golopot
authored andcommitted
feat(check-tag-names): allow undocumented jsdoc modifies tag and missing closure tags
1 parent c0f4494 commit e791ec3

File tree

4 files changed

+176
-11
lines changed

4 files changed

+176
-11
lines changed

.README/rules/check-tag-names.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ memberof
4747
memberof!
4848
mixes
4949
mixin
50+
modifies (Currently undocumented but in source)
5051
module
5152
name
5253
namespace
@@ -75,6 +76,62 @@ version
7576
yields
7677
```
7778

79+
The following synonyms are also recognized:
80+
81+
```
82+
arg
83+
argument
84+
const
85+
constructor
86+
defaultvalue
87+
desc
88+
emits
89+
exception
90+
extends
91+
fileoverview
92+
func
93+
host
94+
method
95+
overview
96+
prop
97+
return
98+
var
99+
virtual
100+
yield
101+
```
102+
103+
For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
104+
(or Closure), one may also use the following:
105+
106+
```
107+
template
108+
```
109+
110+
And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#nosideeffects-modifies-thisarguments),
111+
one may also use:
112+
113+
```
114+
define
115+
dict
116+
export
117+
externs
118+
final
119+
implicitCast (casing distinct from that recognized by jsdoc internally)
120+
inheritDoc (casing distinct from that recognized by jsdoc internally)
121+
noalias
122+
nocollapse
123+
nocompile
124+
noinline
125+
nosideeffects
126+
polymer
127+
polymerBehavior
128+
preserve
129+
struct
130+
suppress
131+
template
132+
unrestricted
133+
```
134+
78135
Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.
79136

80137
#### Options
@@ -86,7 +143,7 @@ The format is as follows:
86143

87144
```json
88145
{
89-
"definedTags": ["define", "record"]
146+
"definedTags": ["note", "record"]
90147
}
91148
```
92149

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ memberof
14171417
memberof!
14181418
mixes
14191419
mixin
1420+
modifies (Currently undocumented but in source)
14201421
module
14211422
name
14221423
namespace
@@ -1445,6 +1446,62 @@ version
14451446
yields
14461447
```
14471448

1449+
The following synonyms are also recognized:
1450+
1451+
```
1452+
arg
1453+
argument
1454+
const
1455+
constructor
1456+
defaultvalue
1457+
desc
1458+
emits
1459+
exception
1460+
extends
1461+
fileoverview
1462+
func
1463+
host
1464+
method
1465+
overview
1466+
prop
1467+
return
1468+
var
1469+
virtual
1470+
yield
1471+
```
1472+
1473+
For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
1474+
(or Closure), one may also use the following:
1475+
1476+
```
1477+
template
1478+
```
1479+
1480+
And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#nosideeffects-modifies-thisarguments),
1481+
one may also use:
1482+
1483+
```
1484+
define
1485+
dict
1486+
export
1487+
externs
1488+
final
1489+
implicitCast (casing distinct from that recognized by jsdoc internally)
1490+
inheritDoc (casing distinct from that recognized by jsdoc internally)
1491+
noalias
1492+
nocollapse
1493+
nocompile
1494+
noinline
1495+
nosideeffects
1496+
polymer
1497+
polymerBehavior
1498+
preserve
1499+
struct
1500+
suppress
1501+
template
1502+
unrestricted
1503+
```
1504+
14481505
Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.
14491506

14501507
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-2"></a>
@@ -1458,7 +1515,7 @@ The format is as follows:
14581515

14591516
```json
14601517
{
1461-
"definedTags": ["define", "record"]
1518+
"definedTags": ["note", "record"]
14621519
}
14631520
```
14641521

src/jsdocUtils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import _ from 'lodash';
2-
import tagNames from './tagNames';
2+
import {jsdocTags, closureTags} from './tagNames';
3+
4+
// Todo: Distinguish closure tags
5+
const tagNames = {
6+
...closureTags,
7+
...jsdocTags,
8+
};
39

410
const getFunctionParameterNames = (functionNode : Object) : Array<string> => {
511
const getParamName = (param) => {

src/tagNames.js

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
export default {
1+
const jsdocTagsUndocumented = {
2+
// Undocumented but present; see
3+
// https://github.com/jsdoc/jsdoc/issues/1283#issuecomment-516816802
4+
// https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js#L594
5+
modifies: [],
6+
};
7+
8+
const jsdocTags = {
9+
...jsdocTagsUndocumented,
210
abstract: [
311
'virtual',
412
],
@@ -65,6 +73,7 @@ export default {
6573
'memberof!': [],
6674
mixes: [],
6775
mixin: [],
76+
6877
module: [],
6978
name: [],
7079
namespace: [],
@@ -90,13 +99,6 @@ export default {
9099
static: [],
91100
summary: [],
92101

93-
// `@template` is not part of standard jsdoc on https://jsdoc.app but is
94-
// used by Closure per:
95-
// https://github.com/google/closure-compiler/wiki/Generic-Types
96-
// and by TypeScript per:
97-
// https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc
98-
template: [],
99-
100102
this: [],
101103
throws: [
102104
'exception',
@@ -111,3 +113,46 @@ export default {
111113
'yield',
112114
],
113115
};
116+
117+
const TypeScriptTags = {
118+
// `@template` is also in TypeScript per:
119+
// https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc
120+
template: [],
121+
};
122+
123+
const closureTags = {
124+
...TypeScriptTags,
125+
126+
// From https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler
127+
// These are all recognized in https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js
128+
// except for the experimental `noinline` and the casing differences noted below
129+
130+
// Defined as a synonym of `const` in jsdoc `definitions.js`
131+
define: [],
132+
133+
dict: [],
134+
export: [],
135+
externs: [],
136+
final: [],
137+
138+
// With casing distinct from jsdoc `definitions.js`
139+
implicitCast: [],
140+
141+
// With casing distinct from jsdoc `definitions.js`
142+
inheritDoc: [],
143+
144+
noalias: [],
145+
nocollapse: [],
146+
nocompile: [],
147+
noinline: [],
148+
nosideeffects: [],
149+
polymer: [],
150+
polymerBehavior: [],
151+
preserve: [],
152+
struct: [],
153+
suppress: [],
154+
155+
unrestricted: [],
156+
};
157+
158+
export {jsdocTags, closureTags};

0 commit comments

Comments
 (0)