Skip to content

Commit ce96d3a

Browse files
committed
- 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
1 parent 40a7fc0 commit ce96d3a

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/rules/noUndefinedTypes.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,20 @@ export default iterateJsdoc(({
5151
})
5252

5353
// If the file is a module, concat the variables from the module scope.
54-
.concat(scopeManager.isModule() ? globalScope.childScopes[0].variables.map((variable) => {
55-
return variable.name;
56-
}) : [])
54+
.concat(
55+
56+
// This covers `commonjs` as well as `node`
57+
scopeManager.__options.nodejsScope ||
58+
scopeManager.isModule() ?
59+
globalScope.childScopes.reduce((arr, {variables}) => {
60+
// Flatten
61+
arr.push(...variables);
62+
63+
return arr;
64+
}, []).map(({name}) => {
65+
return name;
66+
}) : []
67+
)
5768
.concat(extraTypes)
5869
.concat(typedefDeclarations);
5970

test/rules/assertions/noUndefinedTypes.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,25 @@ export default {
5858
function quux(foo) {
5959
6060
}
61-
`
61+
`,
62+
env: {
63+
node: true
64+
}
65+
},
66+
{
67+
code: `
68+
const MyType = require('my-library').MyType;
69+
70+
/**
71+
* @param {MyType} foo - Bar.
72+
*/
73+
function quux(foo) {
74+
75+
}
76+
`,
77+
env: {
78+
node: false
79+
}
6280
},
6381
{
6482
code: `

0 commit comments

Comments
 (0)