Skip to content

[prefer-import-tag] Autofix creates import with invalid identifier #1572

@ehoogeveen-medweb

Description

@ehoogeveen-medweb

I have the following jsdoc comment:

/** @type { import('@typescript-eslint/utils').TSESLint.FlatConfig.Config['rules'] } */

The new prefer-import-tag rule suggests replacing the import() with an @import comment. The autofix then generates the following:

/** @import * as @typescript-eslint/utils from '@typescript-eslint/utils'; */

/** @type {@typescript-eslint/utils.TSESLint.FlatConfig.Config['rules']} */

But @typescript-eslint/utils is not a valid identifier. This triggers an escape-inline-tags warning on the first line and a valid-types warning on the second - but more importantly, it doesn't work.

I suggest either disabling the autofix if the package name isn't a valid identifier, or adding some sort of escaping logic.

For example, typescriptEslintUtils would be valid - but that means stripping the @ and producing upper case letters after - and /. More generally you'd need to handle . too for cases like https://www.npmjs.com/package/chart.js and there might be other exceptions, so I don't know if it's worth it (though import()s can be very repetitive, so an autofix is definitely nice to have).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions