Skip to content

Commit

Permalink
fix(imports-as-dependencies): check exports; fixes gajus#1114
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Jun 25, 2023
1 parent 4afc8e6 commit 837efc6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/rules/imports-as-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,9 @@ The following patterns are not considered problems:
/**
* @type {null|import('node:fs').PathLike}
*/

/**
* @type {null|import('eventtargeter').ListenerInfo}
*/
````

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eslint": "8.41.0",
"eslint-config-canonical": "~41.0.4",
"espree": "^9.5.2",
"eventtargeter": "^0.9.0",
"gitdown": "^3.1.5",
"glob": "^10.2.6",
"husky": "^8.0.3",
Expand All @@ -60,6 +61,7 @@
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"open-editor": "^3.0.0",
"resolve.exports": "^2.0.2",
"rimraf": "^5.0.1",
"semantic-release": "^21.0.2",
"typescript": "^5.0.4"
Expand Down
16 changes: 16 additions & 0 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 @@ -11,6 +11,7 @@ import isBuiltinModule from 'is-builtin-module';
import {
join,
} from 'path';
import * as resolve from 'resolve.exports';

/**
* @type {Set<string>|null}
Expand Down Expand Up @@ -103,7 +104,11 @@ export default iterateJsdoc(({
// Ignore
}

if (!pkg || (!pkg.types && !pkg.typings)) {
if (!pkg || (!pkg.types && !pkg.typings && resolve.exports(pkg, undefined, {
conditions: [
'types', 'typings',
],
}) === undefined)) {
mod = `@types/${mod}`;
}

Expand Down
7 changes: 7 additions & 0 deletions test/rules/assertions/importsAsDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,12 @@ export default {
*/
`,
},
{
code: `
/**
* @type {null|import('eventtargeter').ListenerInfo}
*/
`,
},
],
};

0 comments on commit 837efc6

Please sign in to comment.