Skip to content

Commit

Permalink
fix(no-undefined-types): if no scope found, resume checking current…
Browse files Browse the repository at this point in the history
… node for template tags; fixes #578, fixes #579
  • Loading branch information
brettz9 committed Jun 17, 2020
1 parent 0d29a80 commit fed7586
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -6284,6 +6284,25 @@ const init = () => {
return Promise.resolve('success');
}
};
/** Gets a Promise resolved with a given value.
*
* @template ValueType
* @param {ValueType} value Value to resolve.
* @returns {Promise<ValueType>} Promise resolved with value.
*/
exports.resolve1 = function resolve1(value) {
return Promise.resolve(value);
};
// Settings: {"jsdoc":{"mode":"typescript"}}
/**
* A function returning the same type as its argument.
*
* @template ValueType
* @typedef {ValueType} ValueFunc
*/
// Settings: {"jsdoc":{"mode":"typescript"}}
````
Expand Down
25 changes: 15 additions & 10 deletions src/rules/noUndefinedTypes.js
Expand Up @@ -72,23 +72,28 @@ export default iterateJsdoc(({

const ancestorNodes = [];
let currentScope = scopeManager.acquire(node);

while (currentScope && currentScope.block.type !== 'Program') {
ancestorNodes.push(currentScope.block);
currentScope = currentScope.upper;
}

let templateTags = _(ancestorNodes).flatMap((ancestorNode) => {
const commentNode = getJSDocComment(sourceCode, ancestorNode, settings);
if (!commentNode) {
return [];
}
// `currentScope` may be `null` or `Program`, so in such a case,
// we look to present tags instead
let templateTags = ancestorNodes.length ?
_(ancestorNodes).flatMap((ancestorNode) => {
const commentNode = getJSDocComment(sourceCode, ancestorNode, settings);
if (!commentNode) {
return [];
}

const jsdoc = parseComment(commentNode, '');
const jsdoc = parseComment(commentNode, '');

return jsdocUtils.filterTags(jsdoc.tags, (tag) => {
return 'template' === tag.tag;
});
}).value();
return jsdocUtils.filterTags(jsdoc.tags, (tag) => {
return 'template' === tag.tag;
});
}).value() :
utils.getPresentTags('template');

const classJsdoc = utils.getClassJsdoc();
if (classJsdoc?.tags) {
Expand Down
39 changes: 39 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Expand Up @@ -740,5 +740,44 @@ export default {
es6: true,
},
},
{
code: `
/** Gets a Promise resolved with a given value.
*
* @template ValueType
* @param {ValueType} value Value to resolve.
* @returns {Promise<ValueType>} Promise resolved with value.
*/
exports.resolve1 = function resolve1(value) {
return Promise.resolve(value);
};
`,
env: {
es6: true,
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
{
code: `
/**
* A function returning the same type as its argument.
*
* @template ValueType
* @typedef {ValueType} ValueFunc
*/
`,
env: {
es6: true,
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
],
};

0 comments on commit fed7586

Please sign in to comment.