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

This plugin does not report import/extensions and import/no-unresolved errors on import type … constructs #3028

Open
kmoschcau opened this issue Jul 14, 2024 · 3 comments

Comments

@kmoschcau
Copy link

Assuming we force extensions "always", I get the following results:

import type Foo from "foo"; // No errors reported.
import type { Bar } from "bar"; // No errors reported.
import Foo from "foo"; // Errors reported.
import { type Bar } from "bar"; // Errors reported.

This is not ideal, since I mostly deal with .d.mts files in the project where this occurs. And typescript enforces import type on any .d.ts and .d.mts files.

This is the .eslintrc.cjs of the project:

module.exports = {
  env: {
    es6: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended",
    "plugin:import/recommended",
    "plugin:import/typescript",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "./tsconfig.eslint.json",
    sourceType: "module",
  },
  plugins: ["@typescript-eslint", "eslint-plugin-tsdoc", "import"],
  rules: {
    "@typescript-eslint/ban-types": "off",
    "@typescript-eslint/no-explicit-any": "off",
    "@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
    "@typescript-eslint/no-unsafe-declaration-merging": "off", // TODO: reenable in V10
    "import/extensions": ["error", "always"],
    "tsdoc/syntax": "warn",
  },
  settings: {
    "import/parsers": {
      "@typescript-eslint/parser": [".mts", ".ts"],
    },
    "import/resolver": {
      typescript: {
        alwaysTryTypes: true,
      },
    },
  },
};
@kmoschcau kmoschcau changed the title This plugin does not report any errors on import type … constructs This plugin does not report import/extensions and import/no-unresolved errors on import type … constructs Jul 14, 2024
@ljharb
Copy link
Member

ljharb commented Jul 14, 2024

tsc itself would fail on those, no?

@kmoschcau
Copy link
Author

kmoschcau commented Jul 14, 2024

No it does not. In fact it requires import type on any declaration file imports with specific tsconfig settings.

@aduh95
Copy link

aduh95 commented Aug 14, 2024

I can confirm tsc does not report those. Here's the rule I added to enforce use of extension in import type declarations in case that helps someone else .

        'no-restricted-syntax': ['error', {
          selector: 'ImportDeclaration[importKind="type"][source.value=/^\\.\\.?\\x2F.+\\.js$/]',
          message: 'Do not use ".js" file extension for relative import type declarations',
        }],

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

No branches or pull requests

3 participants