Skip to content

Commit

Permalink
fix(no-undefined-types): avoid checking private member of scopeMana…
Browse files Browse the repository at this point in the history
…ger; fixes #629

Also updates typescript dev. version
  • Loading branch information
brettz9 committed Sep 2, 2020
1 parent 96d5cab commit d900a70
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .ncurc.js
Expand Up @@ -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'],
};
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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';
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions src/rules/noUndefinedTypes.js
Expand Up @@ -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}) => {
Expand Down
15 changes: 15 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Expand Up @@ -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,
},
Expand Down

0 comments on commit d900a70

Please sign in to comment.