Skip to content

new rule: prefer-import-tag #1314

Open
Open
@boneskull

Description

@boneskull

Motivation

I have a codebase littered with inline type-level imports (e.g., @type {import('foo').bar}). I'd like to be able to put a halt to this madness and use import tags instead. I would especially like this to be a fixable rule.

Current behavior

It's the wild west out there

Desired behavior

A rule which could raise an error if an inline type import was detected. Default behavior of this rule, when enabled, would be to always prefer import tags over inline imports.

Highly desired, but not required for a first pass:

  • automatically fixable (though this may be difficult or dangerous, because it will introduce symbols into the module scope [insofar as TS is concerned] and symbols can conflict)

Optionally:

  • inline imports could be preferred over import tags
  • exceptions based on some criteria (e.g., imports from foo are an exception to the configured behavior)

Alternatives considered

  • While TS itself supports JSDoc, typescript-eslint does not and will not support JSDoc.
  • I thought about writing a codemod but that seems too complicated.

I am unsure how feasible this is or how difficult an implementation would be, so I apologize in advance if it's ridiculous.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions