Skip to content

Module namepath #590

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
Jun 23, 2020
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
10 changes: 5 additions & 5 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ how many line breaks to add when a block is missing.
containing both JavaScript and TypeScript, you can also use [`overrides`](https://eslint.org/docs/user-guide/configuring). You may also set to `"permissive"` to
try to be as accommodating to any of the styles, but this is not recommended.
Currently is used for the following:
- Determine valid tags and aliases for `check-tag-names`
- Only check `@template` in `no-undefined-types` for types in "closure" and
- `check-tag-names`: Determine valid tags and aliases
- `no-undefined-types`: Only check `@template` 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,
- `check-syntax`: determines aspects that may be enforced
- For type/namepath-checking rules, determine which tags will be checked for
types/namepaths (Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode)
- For type-checking rules, impacts parsing of types (through
[jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser) dependency)
- Check preferred tag names
- For `check-syntax`, determines aspects that may be enforced
- Disallows namepath on `@interface` for "closure" mode in `valid-types` (and
avoids checking in other rules)

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ how many line breaks to add when a block is missing.
containing both JavaScript and TypeScript, you can also use [`overrides`](https://eslint.org/docs/user-guide/configuring). You may also set to `"permissive"` to
try to be as accommodating to any of the styles, but this is not recommended.
Currently is used for the following:
- Determine valid tags and aliases for `check-tag-names`
- Only check `@template` in `no-undefined-types` for types in "closure" and
- `check-tag-names`: Determine valid tags and aliases
- `no-undefined-types`: Only check `@template` 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,
- `check-syntax`: determines aspects that may be enforced
- For type/namepath-checking rules, determine which tags will be checked for
types/namepaths (Closure allows types on some tags which the others do not,
so these tags will additionally be checked in "closure" mode)
- For type-checking rules, impacts parsing of types (through
[jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser) dependency)
- Check preferred tag names
- For `check-syntax`, determines aspects that may be enforced
- Disallows namepath on `@interface` for "closure" mode in `valid-types` (and
avoids checking in other rules)

Expand Down Expand Up @@ -13478,6 +13478,12 @@ function foo(bar) {}
// Settings: {"jsdoc":{"mode":"jsdoc"}}
// Message: Syntax error in namepath: name<

/**
* @module name<
*/
// Settings: {"jsdoc":{"mode":"jsdoc"}}
// Message: Syntax error in namepath: name<

/**
* @interface name
*/
Expand Down
43 changes: 32 additions & 11 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,28 @@ const closureNamepathDefiningTags = new Set([
'mixin',
'namespace',

// Todo: Should add `module` here (with optional "name" and no curly brackets);
// this block impacts `no-undefined-types` and `valid-types` (search for
// "isNamepathDefiningTag|tagMightHaveNamePosition|tagMightHaveEitherTypeOrNamePosition")

// These seem to all require a "namepath" in their signatures (with no counter-examples)
'name',
'typedef',
'callback',
]);
const namepathDefiningTags = new Set([

const typescriptNamepathDefiningTags = new Set([
...closureNamepathDefiningTags,

// Allows for "name" in signature, but indicates as optional
'interface',
]);

const namepathDefiningTags = new Set([
...typescriptNamepathDefiningTags,

// Optional "name" and no curly brackets
// this block impacts `no-undefined-types` and `valid-types` (search for
// "isNamepathDefiningTag|tagMightHaveNamePosition|tagMightHaveEitherTypeOrNamePosition")
'module',
]);

const tagsWithOptionalNamePositionBase = new Set([
'param',

Expand Down Expand Up @@ -443,6 +449,11 @@ const tagsWithOptionalNamePosition = new Set([
...tagsWithOptionalNamePositionBase,
]);

const typescriptTagsWithOptionalNamePosition = new Set([
...typescriptNamepathDefiningTags,
...tagsWithOptionalNamePositionBase,
]);

const closureTagsWithOptionalNamePosition = new Set([
...closureNamepathDefiningTags,
...tagsWithOptionalNamePositionBase,
Expand Down Expand Up @@ -480,9 +491,14 @@ const tagsWithMandatoryTypeOrNamePosition = new Set([
]);

const isNamepathDefiningTag = (mode, tagName) => {
return mode === 'closure' ?
closureNamepathDefiningTags.has(tagName) :
namepathDefiningTags.has(tagName);
if (mode === 'closure') {
return closureNamepathDefiningTags.has(tagName);
}
if (mode === 'typescript') {
return typescriptNamepathDefiningTags.has(tagName);
}

return namepathDefiningTags.has(tagName);
};

const tagMightHaveTypePosition = (mode, tag) => {
Expand All @@ -504,9 +520,14 @@ const tagMustHaveTypePosition = (mode, tag) => {
};

const tagMightHaveNamePosition = (mode, tag) => {
return mode === 'closure' ?
closureTagsWithOptionalNamePosition.has(tag) :
tagsWithOptionalNamePosition.has(tag);
if (mode === 'closure') {
return closureTagsWithOptionalNamePosition.has(tag);
}
if (mode === 'typescript') {
return typescriptTagsWithOptionalNamePosition.has(tag);
}

return tagsWithOptionalNamePosition.has(tag);
};

const tagMustHaveNamePosition = (tag) => {
Expand Down
17 changes: 17 additions & 0 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,23 @@ export default {
},
},
},
{
code: `
/**
* @module name<
*/
`,
errors: [
{
message: 'Syntax error in namepath: name<',
},
],
settings: {
jsdoc: {
mode: 'jsdoc',
},
},
},
{
code: `
/**
Expand Down