From ce96d3a55b3ca0dd890a7fa16fe69fbf95d19b5b Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Tue, 14 May 2019 22:54:49 +0800 Subject: [PATCH 1/4] - Consider Node.js/Commonjs as module (including variables in module scope as well as global) - Testing: add one test with node false and another with node true --- src/rules/noUndefinedTypes.js | 17 ++++++++++++++--- test/rules/assertions/noUndefinedTypes.js | 20 +++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index 18728b604..4e85156d4 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -51,9 +51,20 @@ export default iterateJsdoc(({ }) // If the file is a module, concat the variables from the module scope. - .concat(scopeManager.isModule() ? globalScope.childScopes[0].variables.map((variable) => { - return variable.name; - }) : []) + .concat( + + // This covers `commonjs` as well as `node` + scopeManager.__options.nodejsScope || + scopeManager.isModule() ? + globalScope.childScopes.reduce((arr, {variables}) => { + // Flatten + arr.push(...variables); + + return arr; + }, []).map(({name}) => { + return name; + }) : [] + ) .concat(extraTypes) .concat(typedefDeclarations); diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index 205b7798c..6a9b701a9 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -58,7 +58,25 @@ export default { function quux(foo) { } - ` + `, + env: { + node: true + } + }, + { + code: ` + const MyType = require('my-library').MyType; + + /** + * @param {MyType} foo - Bar. + */ + function quux(foo) { + + } + `, + env: { + node: false + } }, { code: ` From 0c596b2bf73a44e167c45fb8e0ec32792d503ff3 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Tue, 14 May 2019 22:54:49 +0800 Subject: [PATCH 2/4] docs: generate docs --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 3cd5c094f..02b8d6ed8 100644 --- a/README.md +++ b/README.md @@ -1391,6 +1391,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'; /** From 2d402ec2677138718093975b4f8d77493b6eda9d Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 15 May 2019 07:49:31 +0800 Subject: [PATCH 3/4] Add test case for `Promise`; use preferred `globals` --- test/rules/assertions/noUndefinedTypes.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index 6a9b701a9..7ebf24449 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -31,6 +31,19 @@ export default { } ` }, + { + code: ` + /** + * @param {Promise} foo - Bar. + */ + function quux(foo) { + + } + `, + env: { + es6: true + } + }, { code: ` class MyClass {} @@ -97,7 +110,7 @@ export default { }, { code: ` - /*global MyType*/ + /*globals MyType*/ /** * @param {MyType} foo - Bar. From 7307d354bd3f4e3fb90537be6d751608701b7d08 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 15 May 2019 07:49:31 +0800 Subject: [PATCH 4/4] docs: generate docs --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02b8d6ed8..d38623955 100644 --- a/README.md +++ b/README.md @@ -1371,6 +1371,13 @@ function quux(foo) { } +/** + * @param {Promise} foo - Bar. + */ +function quux(foo) { + +} + class MyClass {} /** @@ -1411,7 +1418,7 @@ import {MyType} from 'my-library'; } -/*global MyType*/ +/*globals MyType*/ /** * @param {MyType} foo - Bar.