Skip to content

Commit 94464cd

Browse files
bary12gajus
authored andcommitted
fix: 'Object' and 'Array' are undefined in sourceType: module (#71)
1 parent c206a9e commit 94464cd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/rules/noUndefinedTypes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default iterateJsdoc(({
1111
sourceCode
1212
}) => {
1313
const scopeManager = sourceCode.scopeManager;
14-
const globalScope = scopeManager.isModule() ? scopeManager.globalScope.childScopes[0] : scopeManager.globalScope;
14+
const globalScope = scopeManager.globalScope;
1515

1616
const typedefDeclarations = _(context.getAllComments())
1717
.filter((comment) => {
@@ -31,6 +31,11 @@ export default iterateJsdoc(({
3131
const definedTypes = globalScope.variables.map((variable) => {
3232
return variable.name;
3333
})
34+
35+
// If the file is a module, concat the variables from the module scope.
36+
.concat(scopeManager.isModule() ? globalScope.childScopes[0].variables.map((variable) => {
37+
return variable.name;
38+
}) : [])
3439
.concat(extraTypes)
3540
.concat(typedefDeclarations);
3641

test/rules/assertions/noUndefinedTypes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ export default {
6767
6868
/**
6969
* @param {MyType} foo - Bar.
70+
* @param {Object<string, number>} foo
71+
* @param {Array<string>} baz
7072
*/
71-
function quux(foo) {
73+
function quux(foo, bar, baz) {
7274
7375
}
7476
`,

0 commit comments

Comments
 (0)