From 7469e59e2c02d31226df9b0afcb9fd154c50136e Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 4 Jun 2023 13:15:49 -0700 Subject: [PATCH] fix(`imports-as-dependencies`): allow relative paths Also: - fix: generation of failing/passing examples --- .README/rules/imports-as-dependencies.md | 8 +- docs/rules/imports-as-dependencies.md | 73 ++++++++++++++++++- src/bin/generateRule.js | 8 +- src/rules/importsAsDependencies.js | 4 + .../rules/assertions/importsAsDependencies.js | 7 ++ 5 files changed, 97 insertions(+), 3 deletions(-) diff --git a/.README/rules/imports-as-dependencies.md b/.README/rules/imports-as-dependencies.md index 96850fa24..59ce4bf6a 100644 --- a/.README/rules/imports-as-dependencies.md +++ b/.README/rules/imports-as-dependencies.md @@ -11,4 +11,10 @@ which is not listed in `dependencies` or `devDependencies`. |Settings|| |Options|| - +## Failing examples + + + +## Passing examples + + diff --git a/docs/rules/imports-as-dependencies.md b/docs/rules/imports-as-dependencies.md index d59f92286..6d2130c1c 100644 --- a/docs/rules/imports-as-dependencies.md +++ b/docs/rules/imports-as-dependencies.md @@ -13,4 +13,75 @@ which is not listed in `dependencies` or `devDependencies`. |Settings|| |Options|| - + + +## Failing examples + +The following patterns are considered problems: + +````js +/** + * @type {null|import('sth').SomeApi} + */ +// Message: import points to package which is not found in dependencies + +/** + * @type {null|import('sth').SomeApi} + */ +// Settings: {"jsdoc":{"mode":"permissive"}} +// Message: import points to package which is not found in dependencies + +/** + * @type {null|import('missingpackage/subpackage').SomeApi} + */ +// Message: import points to package which is not found in dependencies + +/** + * @type {null|import('@sth/pkg').SomeApi} + */ +// Message: import points to package which is not found in dependencies +```` + + + + + +## Passing examples + +The following patterns are not considered problems: + +````js +/** + * @type {null|import('eslint').ESLint} + */ + +/** + * @type {null|import('eslint/use-at-your-own-risk').ESLint} + */ + +/** + * @type {null|import('@es-joy/jsdoccomment').InlineTag} + */ + +/** + * @type {null|import(} + */ + +/** + * @type {null|import('esquery').ESQueryOptions} + */ + +/** + * @type {null|import('@es-joy/jsdoccomment').InlineTag| + * import('@es-joy/jsdoccomment').JsdocBlock} + */ + +/** + * @type {null|import('typescript').Program} + */ + +/** + * @type {null|import('./relativePath.js').Program} + */ +```` + diff --git a/src/bin/generateRule.js b/src/bin/generateRule.js index a6b332e0c..9db948ec9 100644 --- a/src/bin/generateRule.js +++ b/src/bin/generateRule.js @@ -127,7 +127,13 @@ export default iterateJsdoc(({ |Settings|| |Options|| - +## Failing examples + + + +## Passing examples + + `; const ruleReadmePath = `./.README/rules/${ruleName}.md`; diff --git a/src/rules/importsAsDependencies.js b/src/rules/importsAsDependencies.js index 61bcad2d3..44630e954 100644 --- a/src/rules/importsAsDependencies.js +++ b/src/rules/importsAsDependencies.js @@ -67,6 +67,10 @@ export default iterateJsdoc(({ /^(@[^/]+\/[^/]+|[^/]+).*$/u, '$1', ); + if ((/^[./]/u).test(mod)) { + return; + } + if (!moduleCheck.has(mod)) { let pkg; try { diff --git a/test/rules/assertions/importsAsDependencies.js b/test/rules/assertions/importsAsDependencies.js index 1c3fbd8b7..86e3b8418 100644 --- a/test/rules/assertions/importsAsDependencies.js +++ b/test/rules/assertions/importsAsDependencies.js @@ -109,5 +109,12 @@ export default { */ `, }, + { + code: ` + /** + * @type {null|import('./relativePath.js').Program} + */ + `, + }, ], };