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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

giladgd
Copy link

@giladgd giladgd commented Nov 18, 2021

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
Copy link
Author

giladgd commented Nov 18, 2021

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

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

@giladgd
Copy link
Author

giladgd commented Jun 1, 2022

Thanks @rosskevin!

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

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

@voxpelli
Copy link

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