From d900a70fd5cc71c0373644dfaab53f9a0a6b08b9 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 2 Sep 2020 08:52:46 +0800 Subject: [PATCH] fix(`no-undefined-types`): avoid checking private member of scopeManager; fixes #629 Also updates typescript dev. version --- .ncurc.js | 3 --- README.md | 9 +++++++++ package.json | 2 +- src/rules/noUndefinedTypes.js | 9 +++++---- test/rules/assertions/noUndefinedTypes.js | 15 +++++++++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.ncurc.js b/.ncurc.js index 0b1b08e3f..2479a8785 100644 --- a/.ncurc.js +++ b/.ncurc.js @@ -5,7 +5,4 @@ module.exports = { // somewhat older versions of `eslint` we still support even // while our devDeps point to a more recent version dep: 'prod,dev,optional,bundle', - - // Todo [@typescript-eslint/parser@>=4]: Not supporting typescript 4 - reject: ['typescript'], }; diff --git a/README.md b/README.md index 1c6bedc39..aa5e9f186 100644 --- a/README.md +++ b/README.md @@ -6674,6 +6674,15 @@ const MyType = require('my-library').MyType; } +const MyType = require('my-library').MyType; + +/** + * @param {MyType} foo - Bar. + */ + function quux(foo) { + +} + import {MyType} from 'my-library'; /** diff --git a/package.json b/package.json index 6ce8794ec..2332a4598 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "nyc": "^15.1.0", "rimraf": "^3.0.2", "semantic-release": "^17.1.1", - "typescript": "^3.9.7" + "typescript": "^4.0.2" }, "engines": { "node": ">=10" diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index 801007f15..acbbce4ff 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -115,16 +115,17 @@ export default iterateJsdoc(({ return utils.parseClosureTemplateTag(tag); }); + // In modules, including Node, there is a global scope at top with the + // Program scope inside + const cjsOrESMScope = globalScope.childScopes[0]?.block.type === 'Program'; + const allDefinedTypes = new Set(globalScope.variables.map(({name}) => { return name; }) // If the file is a module, concat the variables from the module scope. .concat( - - // This covers `commonjs` as well as `node` - scopeManager.__options.nodejsScope || - scopeManager.isModule() ? + cjsOrESMScope ? _.flatMap(globalScope.childScopes, ({variables}) => { return variables; }, []).map(({name}) => { diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index 250771ffe..c3e2a6491 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -431,6 +431,21 @@ export default { } `, + parserOptions: { + sourceType: 'module', + }, + }, + { + code: ` + const MyType = require('my-library').MyType; + + /** + * @param {MyType} foo - Bar. + */ + function quux(foo) { + + } + `, env: { node: true, },