Skip to content

Commit

Permalink
fix(imports-as-dependencies): allow relative paths
Browse files Browse the repository at this point in the history
Also:
- fix: generation of failing/passing examples
  • Loading branch information
brettz9 committed Jun 4, 2023
1 parent e3b0d0c commit 7469e59
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .README/rules/imports-as-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ which is not listed in `dependencies` or `devDependencies`.
|Settings||
|Options||

<!-- assertions importsAsDependencies -->
## Failing examples

<!-- assertions-failing importsAsDependencies -->

## Passing examples

<!-- assertions-passing importsAsDependencies -->
73 changes: 72 additions & 1 deletion docs/rules/imports-as-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,75 @@ which is not listed in `dependencies` or `devDependencies`.
|Settings||
|Options||

<!-- assertions importsAsDependencies -->
<a name="user-content-failing-examples"></a>
<a name="failing-examples"></a>
## 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
````



<a name="user-content-passing-examples"></a>
<a name="passing-examples"></a>
## 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}
*/
````

8 changes: 7 additions & 1 deletion src/bin/generateRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export default iterateJsdoc(({
|Settings||
|Options||
<!-- assertions ${camelCasedRuleName} -->
## Failing examples
<!-- assertions-failing ${camelCasedRuleName} -->
## Passing examples
<!-- assertions-passing ${camelCasedRuleName} -->
`;

const ruleReadmePath = `./.README/rules/${ruleName}.md`;
Expand Down
4 changes: 4 additions & 0 deletions src/rules/importsAsDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export default iterateJsdoc(({
/^(@[^/]+\/[^/]+|[^/]+).*$/u, '$1',
);

if ((/^[./]/u).test(mod)) {
return;
}

if (!moduleCheck.has(mod)) {
let pkg;
try {
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 @@ -109,5 +109,12 @@ export default {
*/
`,
},
{
code: `
/**
* @type {null|import('./relativePath.js').Program}
*/
`,
},
],
};

0 comments on commit 7469e59

Please sign in to comment.