Skip to content

🐞 [bugfix] Add proper file extensions when importing a typescript file from a typescript file#303

Open
giladgd wants to merge 1 commit into
mysticatea:masterfrom
giladgd:dev/giladgd/fixImportExtentionFixingInTypeScript
Open

🐞 [bugfix] Add proper file extensions when importing a typescript file from a typescript file#303
giladgd wants to merge 1 commit into
mysticatea:masterfrom
giladgd:dev/giladgd/fixImportExtentionFixingInTypeScript

Conversation

@giladgd

@giladgd giladgd commented Nov 18, 2021

Copy link
Copy Markdown

The current situation

Given this configuration:

{
    "node/file-extension-in-import": ["error", "always"]
}

And this file: (a typescript file that imports from another typescript file)

// file1.ts
import something from "./file2"

eslint will suggest adding .ts extension to the import statement, which is invalid and breaks the compilation of typescript.

The fix

When a typescript file (.ts / .cts / .mts files, .cts and .mts will be supported as of TypeScript 4.5) imports another typescript file, eslint will now use the proper matching file extension instead of the original referenced file extension.

This means that, for example, when a .ts file imports another .ts file, eslint will suggest using a .js extension in the import statement.

…erly add the right file extension when importing a typescript file from a typescript file.

The current implementation is breaking typescript code.
@giladgd

giladgd commented Nov 18, 2021

Copy link
Copy Markdown
Author

This would fix the problem that caused xojs/xo#522.
This would also provide an elegant solution to microsoft/TypeScript#16577.

@giladgd giladgd changed the title [bugfix] Add proper file extensions when importing a typescript file from a typescript file 🐞 [bugfix] Add proper file extensions when importing a typescript file from a typescript file Jan 11, 2022
rosskevin added a commit to rosskevin/eslint-plugin-node that referenced this pull request Jun 1, 2022
@rosskevin

Copy link
Copy Markdown

@giladgd I have cherry picked and submitted your fix to the new repo which is being maintained: eslint-community#20

@giladgd

giladgd commented Jun 1, 2022

Copy link
Copy Markdown
Author

Thanks @rosskevin!

aladdin-add pushed a commit to eslint-community/eslint-plugin-n that referenced this pull request Jun 2, 2022
@SamuelGaona

Copy link
Copy Markdown

Is this working? Because i'm still getting .ts extensions on --fix.

@voxpelli

Copy link
Copy Markdown

eslint-plugin-n is the maintained version of this module.

We switched to it in eg. eslint-config-standard / standard and it is maintained by me and other members of the official ESLint community organization.

Try that module out and if it isn't fixed there, then open a new PR in that project.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants