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

[file-extension-in-import] Does not work properly in TypeScript projects with allowImportingTsExtensions #134

Closed
1 task
Zamiell opened this issue Oct 31, 2023 · 3 comments · Fixed by #139
Closed
1 task
Assignees

Comments

@Zamiell
Copy link

Zamiell commented Oct 31, 2023

Environment

Hello,

With the following config:

"n/file-extension-in-import": ["error", "always"],

Will autofix this:

import { foo } from "./foo";

To this:

import { foo } from "./foo.js";

However, this is a bug in TypeScript projects that use allowImportingTsExtensions. In such projects, having a ".js" import is a bug, because the assumption is that our entire application is written in TypeScript, and no JavaScript files will probably ever exist.

Proposal:

Instead of fixing to .js, the rule should auto-fix to .ts when the "tsconfig.json" has the allowImportingTsExtensions option set to true.

What rule do you want to report?

file-extension-in-import

Participation

  • I am willing to submit a pull request for this issue.
@scagood
Copy link

scagood commented Nov 1, 2023

🤔 This makes sense, I will try to look next week. Thanks for the report!

@Zamiell
Copy link
Author

Zamiell commented Dec 19, 2023

@scagood I see that you've fixed the bug on your fork, good work! Anything I can do to move this issue along?

@scagood
Copy link

scagood commented Dec 19, 2023

There are two things holding this back:

  1. I need to make some fixes (in feat!: Start using enhanced-resolve to improve ts support #139) specifically it looks like I may have broken the file-extension-in-import rule.
  2. We want to wait for eslint v9 to be released so we're sure that the plugin is stable with that release before we introduce some possible breaking changes.

I should get some time on Thursday to look into the broken rule problem.

scagood added a commit to scagood/eslint-plugin-n that referenced this issue Jan 2, 2024
scagood added a commit to scagood/eslint-plugin-n that referenced this issue Jan 9, 2024
aladdin-add added a commit that referenced this issue Jan 9, 2024
* feat: Use enhanced-resolve for imports

* chore: Improve the metadata from "ImportTarget"

* chore: remove "enhanced-resolve" from "no-hide-core-modules"

* test: Add a test for #66

* feat!: Allow ts paths aliases (#84)

* feat: Allow for "allowImportingTsExtensions" (#134)

* feat: Add test for import maps (#147)

* Update lib/util/import-target.js

Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>

* test: Add test for n/no-missing-require eslint/use-at-your-own-risk

* chore: Remove esbuild

* feat: Allow for settings.cwd to be used before process.cwd

* chore: replace reference to eslint/use-at-your-own-risk

* chore: Remove more unused packages

* chore: update rule test options to flat config

* fix: incorrect env in tests

---------

Co-authored-by: 唯然 <weiran.zsd@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants