gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.07k stars 155 forks source link

`valid-types`: Handle inline imported TypeScript types #1210

Closed yvele closed 4 months ago

yvele commented 4 months ago

Motivation

Maybe related to https://github.com/gajus/eslint-plugin-jsdoc/issues/145

I'm using JavaScript (not TypeScript), but I still want to import TypeScript type in inline fashion.

Current behavior

Using:

/**
 * @returns {import("@slack/web/api").ChatPostMessageArguments}
 */

or

/**
 * @typedef {import("@slack/web/api").ChatPostMessageArguments} ChatPostMessageArguments
 */

Triggers the following error:

error Syntax error in type: import("@slack/web/api").ChatPostMessageArguments jsdoc/valid-types

Desired behavior

I want the ESLint JSDoc plugin to consider the inline TypeScript import as valid (although coding in JavaScript).

Note that Visual Studio code automatically created the @returns {import("@slack/web/api").ChatPostMessageArguments} so I consider it as valid.

Alternatives considered

/* eslint-disable jsdoc/valid-types */
/**
 * @returns {import("@slack/web/api").ChatPostMessageArguments}
 */
/* eslint-enable jsdoc/valid-types */

🤷

Any better workaround?

brettz9 commented 4 months ago

Do you have settings: {jsdoc: {mode: 'jsdoc'}} set? It should instead be either omitted or explicitly set to the default of settings: {jsdoc: {mode: 'typescript'}}.

This mode is for the TypeScript flavor of JSDoc, not necessarily for TypeScript syntax, so you can use it inside of JavaScript files. The "jsdoc" mode is for the original https://jsdoc.app syntax only.

yvele commented 4 months ago

How yeah right I was using jsdoc mode. I've removed it (implicit typescript mode) and everything works fine.

Thank you @brettz9 ❤️