Skip to content

Commit

Permalink
fix(imports-as-dependencies): support Node builtins; fixes #1112
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Jun 6, 2023
1 parent 7469e59 commit ab00592
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 23 deletions.
12 changes: 12 additions & 0 deletions docs/rules/imports-as-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,17 @@ The following patterns are not considered problems:
/**
* @type {null|import('./relativePath.js').Program}
*/

/**
* @type {null|import('fs').PathLike}
*/

/**
* @type {null|import('fs/promises').FileHandle}
*/

/**
* @type {null|import('node:fs').PathLike}
*/
````

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"debug": "^4.3.4",
"escape-string-regexp": "^4.0.0",
"esquery": "^1.5.0",
"is-builtin-module": "^3.2.1",
"semver": "^7.5.1",
"spdx-expression-parse": "^3.0.1"
},
Expand All @@ -37,7 +38,7 @@
"@types/estree": "^1.0.1",
"@types/lodash.defaultsdeep": "^4.6.7",
"@types/mocha": "^10.0.1",
"@types/node": "^20.2.3",
"@types/node": "^20.2.5",
"@types/semver": "^7.5.0",
"@types/spdx-expression-parse": "^3.0.2",
"@typescript-eslint/parser": "^5.59.6",
Expand Down
47 changes: 26 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/rules/importsAsDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {
readFileSync,
} from 'fs';
import isBuiltinModule from 'is-builtin-module';
import {
join,
} from 'path';
Expand Down Expand Up @@ -71,7 +72,11 @@ export default iterateJsdoc(({
return;
}

if (!moduleCheck.has(mod)) {
if (isBuiltinModule(mod)) {
// mod = '@types/node';
// moduleCheck.set(mod, !deps.has(mod));
return;
} else if (!moduleCheck.has(mod)) {
let pkg;
try {
pkg = JSON.parse(
Expand Down
21 changes: 21 additions & 0 deletions test/rules/assertions/importsAsDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,26 @@ export default {
*/
`,
},
{
code: `
/**
* @type {null|import('fs').PathLike}
*/
`,
},
{
code: `
/**
* @type {null|import('fs/promises').FileHandle}
*/
`,
},
{
code: `
/**
* @type {null|import('node:fs').PathLike}
*/
`,
},
],
};

0 comments on commit ab00592

Please sign in to comment.