gajus / eslint-plugin-jsdoc

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

Add support for `@import` #1226

Closed Arkellys closed 2 months ago

Arkellys commented 2 months ago

Clone of this feature request, originally posted on jsdoc-type-pratt-parser.

Motivation

Typescript v5.5 introduces the tag @import, which allows importing types (or other stuff) within JSDoc:

/** @import { SomeType } from "some-module" */

Would it be possible to add support for this new syntax?

Current behavior

With mode: "typescript"

types.js

export const allowImports = true; // Trick to allow importing

/** @typedef {string} TestOne */
/** @typedef {string} TestTwo */

other.js

/**
 * @import { TestOne, TestTwo } from "./types"  🡒  Syntax error in type: TestOne, TestTwo eslint(jsdoc/valid-types)
 * @import { TestOne } from "./types"  🡒  The type 'TestOne' is undefined. eslint(jsdoc/no-undefined-types)
 * @import * as Types from "./types"  🡒  No error
 */

// And regardless of the import used: 

/** 
 * @typedef {TestOne} Test  🡒  The type 'TestOne' is undefined. eslint(jsdoc/no-undefined-types)
 */ 

Except for the errors, the imports works well.

Desired behavior

Being able to use @import without errors.

brettz9 commented 2 months ago

To replicate, I will need your full ESLint config and details (e.g., version of eslint-plugin-jsdoc).

Arkellys commented 2 months ago

To replicate, I will need your full ESLint config and details (e.g., version of eslint-plugin-jsdoc).

Oh yes sorry, I put it on the other issue and I forgot to add it here, my full config + version used is available on this repository. The JSDoc config specifically is on this file.

To use the latest TypeScript features, I'm using the VSCode plugin JavaScript and TypeScript Nightly.

brettz9 commented 2 months ago

The import issue should be fixed in v48.2.3.

brettz9 commented 2 months ago

Sorry, got confused. It doesn't fix it.

github-actions[bot] commented 2 months ago

:tada: This issue has been resolved in version 48.2.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

brettz9 commented 2 months ago

The no-undefined-types rule is currently discouraged if you are using TypeScript checking (which checks for undefined types anyways). If you change your config to "recommended-typescript-flavor" or "recommended-typescript-flavor-error" (for JavaScript; if using TypeScript syntax, use "recommended-typescript" or "recommended-typescript-error"), this rule will be disabled and you will not see the error.

Arkellys commented 2 months ago

All right, thank you for the information, and the fix! I'll see about adjusting my configuration. 🙂