Skip to content

Only check @template in no-undefined-types for types in "closure" and "typescript" modes #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ You can then selectively add to or override the recommended rules.
### Mode

- `settings.jsdoc.mode` - Set to `jsdoc` (the default), `typescript`, or `closure`.
Currently is used for checking preferred tag names and in the `check-tag-names`
rule. For type-checking rules, the setting also determines which tags will be
checked for types (Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode).
Currently is used for the following:
- Determine valid tags for `check-tag-names`
- Only check `@template` in `no-undefined-types` for types in "closure" and
"typescript" modes
- For type-checking rules, determine which tags will be checked for types
(Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode)
- Check preferred tag names

### Alias Preference

Expand Down
2 changes: 1 addition & 1 deletion .README/rules/no-undefined-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In addition to considering globals found in code (or in ESLint-indicated
name(path) definitions to also serve as a potential "type" for checking
the tag types in the table below:

`@callback`, `@class` (or `@constructor`), `@constant` (or `@const`), `@event`, `@external` (or `@host`), `@function` (or `@func` or `@method`), `@interface`, `@member` (or `@var`), `@mixin`, `@name`, `@namespace`, `@template` (for Closure/TypeScript), `@typedef`.
`@callback`, `@class` (or `@constructor`), `@constant` (or `@const`), `@event`, `@external` (or `@host`), `@function` (or `@func` or `@method`), `@interface`, `@member` (or `@var`), `@mixin`, `@name`, `@namespace`, `@template` (for "closure" or "typescript" `settings.jsdoc.mode` only), `@typedef`.

The following tags will also be checked but only when the mode is `closure`:

Expand Down
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ You can then selectively add to or override the recommended rules.
### Mode

- `settings.jsdoc.mode` - Set to `jsdoc` (the default), `typescript`, or `closure`.
Currently is used for checking preferred tag names and in the `check-tag-names`
rule. For type-checking rules, the setting also determines which tags will be
checked for types (Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode).
Currently is used for the following:
- Determine valid tags for `check-tag-names`
- Only check `@template` in `no-undefined-types` for types in "closure" and
"typescript" modes
- For type-checking rules, determine which tags will be checked for types
(Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode)
- Check preferred tag names

<a name="eslint-plugin-jsdoc-settings-alias-preference"></a>
### Alias Preference
Expand Down Expand Up @@ -3915,7 +3919,7 @@ In addition to considering globals found in code (or in ESLint-indicated
name(path) definitions to also serve as a potential "type" for checking
the tag types in the table below:

`@callback`, `@class` (or `@constructor`), `@constant` (or `@const`), `@event`, `@external` (or `@host`), `@function` (or `@func` or `@method`), `@interface`, `@member` (or `@var`), `@mixin`, `@name`, `@namespace`, `@template` (for Closure/TypeScript), `@typedef`.
`@callback`, `@class` (or `@constructor`), `@constant` (or `@const`), `@event`, `@external` (or `@host`), `@function` (or `@func` or `@method`), `@interface`, `@member` (or `@var`), `@mixin`, `@name`, `@namespace`, `@template` (for "closure" or "typescript" `settings.jsdoc.mode` only), `@typedef`.

The following tags will also be checked but only when the mode is `closure`:

Expand Down Expand Up @@ -4018,6 +4022,7 @@ function quux(foo, bar, baz) {
*/
function foo (bar) {
};
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: The type 'WRONG_TEMPLATE_TYPE' is undefined.

class Foo {
Expand Down Expand Up @@ -4047,6 +4052,7 @@ class Bar {
validTemplateReference () {
}
}
// Settings: {"jsdoc":{"mode":"typescript"}}
// Message: The type 'TEMPLATE_TYPE' is undefined.

/**
Expand All @@ -4056,6 +4062,19 @@ var quux = {

};
// Message: The type 'strnig' is undefined.

/**
* @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
*/
class Foo {
/**
* @param {TEMPLATE_TYPE_A} baz
* @return {TEMPLATE_TYPE_B}
*/
bar (baz) {
}
}
// Message: The type 'TEMPLATE_TYPE_A' is undefined.
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -4213,6 +4232,7 @@ function quux(foo, bar, baz) {
*/
function foo (bar) {
};
// Settings: {"jsdoc":{"mode":"closure"}}

/**
* @template TEMPLATE_TYPE
Expand All @@ -4224,6 +4244,7 @@ class Foo {
bar () {
}
}
// Settings: {"jsdoc":{"mode":"closure"}}

/**
* @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
Expand All @@ -4236,6 +4257,7 @@ class Foo {
bar (baz) {
}
}
// Settings: {"jsdoc":{"mode":"closure"}}

/****/

Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default iterateJsdoc(({
.concat(typedefDeclarations)
.concat(definedTypes)
.concat(definedPreferredTypes)
.concat(closureGenericTypes);
.concat(settings.mode === 'jsdoc' ? [] : closureGenericTypes);

const jsdocTagsWithPossibleType = utils.filterTags((tag) => {
return utils.tagMightHaveAType(tag.tag);
Expand Down
48 changes: 48 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export default {
message: 'The type \'WRONG_TEMPLATE_TYPE\' is undefined.',
},
],
settings: {
jsdoc: {
mode: 'closure',
},
},
},
{
code: `
Expand Down Expand Up @@ -208,6 +213,11 @@ export default {
message: 'The type \'TEMPLATE_TYPE\' is undefined.',
},
],
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
{
code: `
Expand All @@ -228,6 +238,29 @@ export default {
'no-undef': 'error',
},
},
{
code: `
/**
* @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
*/
class Foo {
/**
* @param {TEMPLATE_TYPE_A} baz
* @return {TEMPLATE_TYPE_B}
*/
bar (baz) {
}
}
`,
errors: [
{
message: 'The type \'TEMPLATE_TYPE_A\' is undefined.',
},
{
message: 'The type \'TEMPLATE_TYPE_B\' is undefined.',
},
],
},
],
valid: [
{
Expand Down Expand Up @@ -472,6 +505,11 @@ export default {
function foo (bar) {
};
`,
settings: {
jsdoc: {
mode: 'closure',
},
},
},
{
code: `
Expand All @@ -486,6 +524,11 @@ export default {
}
}
`,
settings: {
jsdoc: {
mode: 'closure',
},
},
},
{
code: `
Expand All @@ -501,6 +544,11 @@ export default {
}
}
`,
settings: {
jsdoc: {
mode: 'closure',
},
},
},
{
code: `
Expand Down