Skip to content

Commit

Permalink
feat(check-tag-names): allow undocumented jsdoc modifies tag and …
Browse files Browse the repository at this point in the history
…missing closure tags
  • Loading branch information
brettz9 authored and golopot committed Oct 12, 2019
1 parent c0f4494 commit e791ec3
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 11 deletions.
59 changes: 58 additions & 1 deletion .README/rules/check-tag-names.md
Expand Up @@ -47,6 +47,7 @@ memberof
memberof!
mixes
mixin
modifies (Currently undocumented but in source)
module
name
namespace
Expand Down Expand Up @@ -75,6 +76,62 @@ version
yields
```

The following synonyms are also recognized:

```
arg
argument
const
constructor
defaultvalue
desc
emits
exception
extends
fileoverview
func
host
method
overview
prop
return
var
virtual
yield
```

For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
(or Closure), one may also use the following:

```
template
```

And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#nosideeffects-modifies-thisarguments),
one may also use:

```
define
dict
export
externs
final
implicitCast (casing distinct from that recognized by jsdoc internally)
inheritDoc (casing distinct from that recognized by jsdoc internally)
noalias
nocollapse
nocompile
noinline
nosideeffects
polymer
polymerBehavior
preserve
struct
suppress
template
unrestricted
```

Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.

#### Options
Expand All @@ -86,7 +143,7 @@ The format is as follows:

```json
{
"definedTags": ["define", "record"]
"definedTags": ["note", "record"]
}
```

Expand Down
59 changes: 58 additions & 1 deletion README.md
Expand Up @@ -1417,6 +1417,7 @@ memberof
memberof!
mixes
mixin
modifies (Currently undocumented but in source)
module
name
namespace
Expand Down Expand Up @@ -1445,6 +1446,62 @@ version
yields
```

The following synonyms are also recognized:

```
arg
argument
const
constructor
defaultvalue
desc
emits
exception
extends
fileoverview
func
host
method
overview
prop
return
var
virtual
yield
```

For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
(or Closure), one may also use the following:

```
template
```

And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#nosideeffects-modifies-thisarguments),
one may also use:

```
define
dict
export
externs
final
implicitCast (casing distinct from that recognized by jsdoc internally)
inheritDoc (casing distinct from that recognized by jsdoc internally)
noalias
nocollapse
nocompile
noinline
nosideeffects
polymer
polymerBehavior
preserve
struct
suppress
template
unrestricted
```

Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.

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

```json
{
"definedTags": ["define", "record"]
"definedTags": ["note", "record"]
}
```

Expand Down
8 changes: 7 additions & 1 deletion src/jsdocUtils.js
@@ -1,5 +1,11 @@
import _ from 'lodash';
import tagNames from './tagNames';
import {jsdocTags, closureTags} from './tagNames';

// Todo: Distinguish closure tags
const tagNames = {
...closureTags,
...jsdocTags,
};

const getFunctionParameterNames = (functionNode : Object) : Array<string> => {
const getParamName = (param) => {
Expand Down
61 changes: 53 additions & 8 deletions src/tagNames.js
@@ -1,4 +1,12 @@
export default {
const jsdocTagsUndocumented = {
// Undocumented but present; see
// https://github.com/jsdoc/jsdoc/issues/1283#issuecomment-516816802
// https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js#L594
modifies: [],
};

const jsdocTags = {
...jsdocTagsUndocumented,
abstract: [
'virtual',
],
Expand Down Expand Up @@ -65,6 +73,7 @@ export default {
'memberof!': [],
mixes: [],
mixin: [],

module: [],
name: [],
namespace: [],
Expand All @@ -90,13 +99,6 @@ export default {
static: [],
summary: [],

// `@template` is not part of standard jsdoc on https://jsdoc.app but is
// used by Closure per:
// https://github.com/google/closure-compiler/wiki/Generic-Types
// and by TypeScript per:
// https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc
template: [],

this: [],
throws: [
'exception',
Expand All @@ -111,3 +113,46 @@ export default {
'yield',
],
};

const TypeScriptTags = {
// `@template` is also in TypeScript per:
// https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc
template: [],
};

const closureTags = {
...TypeScriptTags,

// From https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler
// These are all recognized in https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js
// except for the experimental `noinline` and the casing differences noted below

// Defined as a synonym of `const` in jsdoc `definitions.js`
define: [],

dict: [],
export: [],
externs: [],
final: [],

// With casing distinct from jsdoc `definitions.js`
implicitCast: [],

// With casing distinct from jsdoc `definitions.js`
inheritDoc: [],

noalias: [],
nocollapse: [],
nocompile: [],
noinline: [],
nosideeffects: [],
polymer: [],
polymerBehavior: [],
preserve: [],
struct: [],
suppress: [],

unrestricted: [],
};

export {jsdocTags, closureTags};

0 comments on commit e791ec3

Please sign in to comment.