Skip to content

Commit fceb74c

Browse files
authored
feat(check-tag-names): for "closure" mode, prefer "return" over "returns"; fixes part of #356
1 parent 794aea8 commit fceb74c

File tree

7 files changed

+87
-10
lines changed

7 files changed

+87
-10
lines changed

.README/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ how many line breaks to add when a block is missing.
135135
containing both JavaScript and TypeScript, you can also use [`overrides`](https://eslint.org/docs/user-guide/configuring). You may also set to `"permissive"` to
136136
try to be as accommodating to any of the styles, but this is not recommended.
137137
Currently is used for the following:
138-
- Determine valid tags for `check-tag-names`
138+
- Determine valid tags and aliases for `check-tag-names`
139139
- Only check `@template` in `no-undefined-types` for types in "closure" and
140140
"typescript" modes
141141
- For type-checking rules, determine which tags will be checked for types

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ template
126126

127127
And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler),
128128
when `settings.jsdoc.mode` is set to `closure`, one may use the following (in
129-
addition to the jsdoc and TypeScript tags):
129+
addition to the jsdoc and TypeScript tags–though replacing `returns` with
130+
`return`):
130131

131132
```
132133
define (synonym of `const` per jsdoc source)

.README/rules/valid-types.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
1010
`@class`, `@constructor`, `@constant`, `@const`,
1111
`@function`, `@func`, `@method`, `@interface`, `@member`, `@var`,
1212
`@mixin`, `@namespace`
13-
1. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`, `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
13+
1. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`,
14+
`@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
1415
1. Name(path)-pointing tags (which may have value without namepath or their
1516
namepath can be expressed elsewhere on the block): `@listens`, `@fires`,
1617
`@emits`, and `@modifies`

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ how many line breaks to add when a block is missing.
193193
containing both JavaScript and TypeScript, you can also use [`overrides`](https://eslint.org/docs/user-guide/configuring). You may also set to `"permissive"` to
194194
try to be as accommodating to any of the styles, but this is not recommended.
195195
Currently is used for the following:
196-
- Determine valid tags for `check-tag-names`
196+
- Determine valid tags and aliases for `check-tag-names`
197197
- Only check `@template` in `no-undefined-types` for types in "closure" and
198198
"typescript" modes
199199
- For type-checking rules, determine which tags will be checked for types
@@ -2631,7 +2631,8 @@ template
26312631

26322632
And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler),
26332633
when `settings.jsdoc.mode` is set to `closure`, one may use the following (in
2634-
addition to the jsdoc and TypeScript tags):
2634+
addition to the jsdoc and TypeScript tags–though replacing `returns` with
2635+
`return`):
26352636

26362637
```
26372638
define (synonym of `const` per jsdoc source)
@@ -2863,6 +2864,13 @@ function quux () {
28632864
// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
28642865
// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
28652866

2867+
/**
2868+
* @returns
2869+
*/
2870+
function quux (foo) {}
2871+
// Settings: {"jsdoc":{"mode":"closure"}}
2872+
// Message: Invalid JSDoc tag (preference). Replace "returns" JSDoc tag with "return".
2873+
28662874
/**
28672875
* @modifies
28682876
* @abstract
@@ -3071,6 +3079,17 @@ function quux (foo) {
30713079
}
30723080
// Settings: {"jsdoc":{"tagNamePreference":{"param":"baz","returns":{"message":"Prefer `bar`","replacement":"bar"},"todo":false}}}
30733081

3082+
/**
3083+
* @returns
3084+
*/
3085+
function quux (foo) {}
3086+
3087+
/**
3088+
* @return
3089+
*/
3090+
function quux (foo) {}
3091+
// Settings: {"jsdoc":{"mode":"closure"}}
3092+
30743093
/**
30753094
* @modifies
30763095
* @abstract
@@ -13214,7 +13233,8 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
1321413233
`@class`, `@constructor`, `@constant`, `@const`,
1321513234
`@function`, `@func`, `@method`, `@interface`, `@member`, `@var`,
1321613235
`@mixin`, `@namespace`
13217-
1. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`, `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
13236+
1. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`,
13237+
`@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
1321813238
1. Name(path)-pointing tags (which may have value without namepath or their
1321913239
namepath can be expressed elsewhere on the block): `@listens`, `@fires`,
1322013240
`@emits`, and `@modifies`

src/jsdocUtils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ const getPreferredTagName = (
231231

232232
// Allow keys to have a 'tag ' prefix to avoid upstream bug in ESLint
233233
// that disallows keys that conflict with Object.prototype,
234-
// e.g. 'tag constructor' for 'constructor' (#537)
234+
// e.g. 'tag constructor' for 'constructor':
235+
// https://github.com/eslint/eslint/issues/13289
236+
// https://github.com/gajus/eslint-plugin-jsdoc/issues/537
235237
const tagPreferenceFixed = _.mapKeys(tagPreference, (value, key) => {
236238
return key.replace('tag ', '');
237239
});

src/tagNames.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,17 @@ const undocumentedClosureTags = {
144144
};
145145

146146
const {
147-
// eslint-disable-next-line no-unused-vars
147+
/* eslint-disable no-unused-vars */
148148
inheritdoc,
149-
...typeScriptTagsNoInheritdoc
149+
150+
// Will be inverted to prefer `return`
151+
returns,
152+
/* eslint-enable no-unused-vars */
153+
...typeScriptTagsInClosure
150154
} = typeScriptTags;
151155

152156
const closureTags = {
153-
...typeScriptTagsNoInheritdoc,
157+
...typeScriptTagsInClosure,
154158
...undocumentedClosureTags,
155159

156160
// From https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler
@@ -180,6 +184,10 @@ const closureTags = {
180184
// Defined as a synonym of `interface` in jsdoc `definitions.js`
181185
record: [],
182186

187+
return: [
188+
'returns',
189+
],
190+
183191
struct: [],
184192
suppress: [],
185193

test/rules/assertions/checkTagNames.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,30 @@ export default {
503503
},
504504
},
505505
},
506+
{
507+
code: `
508+
/**
509+
* @returns
510+
*/
511+
function quux (foo) {}
512+
`,
513+
errors: [
514+
{
515+
message: 'Invalid JSDoc tag (preference). Replace "returns" JSDoc tag with "return".',
516+
},
517+
],
518+
output: `
519+
/**
520+
* @return
521+
*/
522+
function quux (foo) {}
523+
`,
524+
settings: {
525+
jsdoc: {
526+
mode: 'closure',
527+
},
528+
},
529+
},
506530
{
507531
code: `${ALL_JSDOC_TAGS_COMMENT}\nfunction quux (foo) {}`,
508532
errors: [
@@ -619,6 +643,27 @@ export default {
619643
},
620644
},
621645
},
646+
{
647+
code: `
648+
/**
649+
* @returns
650+
*/
651+
function quux (foo) {}
652+
`,
653+
},
654+
{
655+
code: `
656+
/**
657+
* @return
658+
*/
659+
function quux (foo) {}
660+
`,
661+
settings: {
662+
jsdoc: {
663+
mode: 'closure',
664+
},
665+
},
666+
},
622667
{
623668
code: `${ALL_JSDOC_TAGS_COMMENT}\nfunction quux (foo) {}`,
624669
},

0 commit comments

Comments
 (0)