You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using JSDoc to define a typedef with an import statement, the linter fails with the rule jsdoc/no-undefined-types when the import statement is referencing a type defined in another file purely based on spacing.
Steps to Reproduce:
Define a JSDoc typedef with an import statement referencing a type from another file, for example:
javascript
/**@typedef {import('restify').Request} Request */ // Passes linter just fine
/**@typedef {import('./types').helperError} helperError */ // Fails linter
Expected Behavior:
The linter should recognize the import statement and not raise any errors for the typedef definition; for the sake of consistency, it should either error on both or error on neither.
Actual Behavior:
The linter fails on the import for helperError with the rule jsdoc/no-undefined-types, indicating that the imported type is undefined, despite being properly recognized by VS Code.
Note that the following works properly and passes the linter:
I'm almost certain that in source code if not in its docs, the original JSDoc tool called for whitespace after the initial /**. However, as you are using the TypeScript mode (now the default also), we'd ideally be using comment parsing as used by TypeScript.
It does seem though that TSDoc, a spec/tool for parsing JSDoc comments for TypeScript, allows for no whitespace. Ideally then, we'd use a tool like @microsoft/tsdoc in place of comment-parser. This might also be useful in a few other edge cases like #1116 .
However, this would most likely require a high degree of refactoring, and it is not one I am inclined to undertake myself (it'd also require changes in @es-joy/jsdoccomment). A PR would be welcome, however.
brettz9
changed the title
Linter Fails with jsdoc/no-undefined-types Rule for Import Statement in JSDoc Typedef due to spacing
jsdoc/no-undefined-types: does not recognize blocks without initial whitespace
Mar 31, 2024
brettz9
changed the title
jsdoc/no-undefined-types: does not recognize blocks without initial whitespace
parser does not recognize JSDoc blocks without initial whitespace
Mar 31, 2024
Description:
When using JSDoc to define a typedef with an import statement, the linter fails with the rule jsdoc/no-undefined-types when the import statement is referencing a type defined in another file purely based on spacing.
Steps to Reproduce:
Define a JSDoc typedef with an import statement referencing a type from another file, for example:
javascript
Expected Behavior:
The linter should recognize the import statement and not raise any errors for the typedef definition; for the sake of consistency, it should either error on both or error on neither.
Actual Behavior:
The linter fails on the import for
helperError
with the rule jsdoc/no-undefined-types, indicating that the imported type is undefined, despite being properly recognized by VS Code.Note that the following works properly and passes the linter:
The behavior is inconsistent.
ESLint Config
Environment
Node version: v18.19.1
ESLint Version: v8.57.0
eslint-plugin-jsdoc
: 48.2.1The text was updated successfully, but these errors were encountered: