Skip to content

feat: autofix extensionless paths with its setting #402

@Zamiell

Description

@Zamiell

Description

The autofixer for the import-x/extensions rule does not seem to work out of the box on v4.16.1.

Reproduction

Copy paste the following into a terminal. (I think that this is probably the simplest possible reproduction.)

mkdir test
cd test
npm init --yes
npm install --save-dev eslint @eslint/js typescript typescript-eslint eslint-plugin-import-x eslint-import-resolver-typescript
echo '// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import { importX } from "eslint-plugin-import-x";

// Following the vanilla instructions from here:
// https://typescript-eslint.io/getting-started
export default tseslint.config(
  eslint.configs.recommended,
  tseslint.configs.recommended,

  // Following the vanilla instructions from here:
  // https://github.com/un-ts/eslint-plugin-import-x/tree/master?tab=readme-ov-file#as-a-standalone-eslint-plugin
  {
    plugins: {
      "import-x": importX,
    },
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
    },
    rules: {
      "import-x/extensions": ["error", "ignorePackages", { fix: true }],
    },
  },
);' > eslint.config.mjs
mkdir src
echo 'export const foo = 123;' > src/foo.ts
echo 'import { foo } from "./foo";

console.log(foo);' > src/main.ts
npx eslint src/main.ts # Reports 1 error, as expected.
npx eslint src/main.ts --fix # Does not fix anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeaturequestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions