Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[import/extensions][TypeScript] Suggestion: set rules for .ts, .tsx, .mts, .cts to 'never' in import/typescript config #2853

Open
OlivierZal opened this issue Aug 8, 2023 · 2 comments

Comments

@OlivierZal
Copy link

OlivierZal commented Aug 8, 2023

I suggest adding this rule to the import/typescript config (<eslint-plugin-import>.configs.typescript.rules):

'import/extensions': [
  'error',
  ignorePackages,
  {
    ts: 'never',
    tsx: 'never',
    mts: 'never',
    cts: 'never',
  },
],

since explicit .ts+ extensions are not allowed in TypeScript (except as on option in the cases of noEmit or emitDeclarationOnly, which are not the dominant tsconfigs – I guess).

So eslint would be prevented from raising an error in the case of an import/extensions rule from another eslint config, which usually rules error with never only for .js+ extensions.

@ljharb FYI, don't hesitate to let know what you think.

@ljharb
Copy link
Member

ljharb commented Aug 17, 2023

That sounds reasonable to me, but we'd need to use overrides so it only applies in TS files, and not in JS files.

@OlivierZal
Copy link
Author

OlivierZal commented Aug 17, 2023

"overrides": [
  {
    "files": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
    "rules": {
      "import/extensions": [
        "error",
        "ignorePackages",
        {
          js: "ignorePackages",
          jsx: "ignorePackages",
          mis: "ignorePackages",
          cjs: "ignorePackages",
          ts: "never",
          tsx: "never",
          mts: "never",
          cts: "never",
        },
      ],
    },
  },
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants