gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.1k stars 159 forks source link

new rule: prefer-import-tag #1314

Open boneskull opened 1 month ago

boneskull commented 1 month ago

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:

Optionally:

Alternatives considered

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

brettz9 commented 1 month ago

You can currently get this without a fixer by using:

'jsdoc/no-restricted-syntax': ['warn', {
  contexts: [
    {
      comment: 'JsdocBlock:has(JsdocTag:has(JsdocTypeImport))',
      context: 'any',
      message: 'Use @import tag over import() statements',
    },
  ],
}]