Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: Add support for TypeScript config files #117
feat: Add support for TypeScript config files #117
Changes from 1 commit
5e5fc4c
50676fa
9ab30b5
c0c0714
247393f
d13d556
5e68795
24dac1d
3863834
d5e16db
0e09c10
3c37a94
e0da6c3
24b0893
ef591fc
7dfea39
de7e87a
fb612ed
f60a15c
fef64ec
6e8440f
2a2c9f8
263c467
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the feature interact with the CLI option
--config
for specifying a config file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested it, so far it seems to work pretty well actually, especially with v9. I'm probably going to write a bunch of tests as well to see if there are any edge cases but so far so good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to explain what the behavior is when specifying TS or non-TS config files of varying file extensions through that option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't behave any differently, same as before. You can do
eslint . --config=eslint.config.ts
oreslint . -c eslint.config.ts
and they just work. Same as with aeslint.config.js
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add that into the RFC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it to the open questions, is that fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a community project: https://github.com/antfu/eslint-ts-patch to support it. would like to hear the author :) / @antfu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses jiti to support ts file. Which already mentioned #117 (comment) that it doesn't currently support top-level await.
I would personally recommend using https://github.com/egoist/bundle-require instead which is more robust and will respect tsconfig.json. The downside is that it would introduce
esbuild
into the dependency. If the install size is a concern, I guess we could have an optional package like@eslint/config-loader-ts
that only requires when users use ts version of config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like @eslint/config-inspector uses bundle-require as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the inspector uses that because we need to know the dependencies of the config to do automatic reloads. Supporting TS was a free side-effect.
Even if ESLint doesn't need information on dependencies, I think it's still a good way to support TS. Vite uses the same approach to load
vite.config.ts
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
bundle-require
write a temp file to disk like vite does?These temp files are a major source of problems with vite, see vitejs/vite#9470.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jiti won't recognize TLA not only in the config file itself, but also in imported modules, because they are all treated as CommonJS. I did a quick test using a patched version of ESLint with the changes from #18134 and with this config:
When running
eslint
, I got an error as expected:The workaround of using a dynamic import didn't help either, and resulted in the same error:
This means that if we decide to use Jiti, plugin developers should be advised to avoid TLA in their shared configs (including rules and transitive dependencies), or else those configs will not work for users who have a
eslint.config.ts
in their project.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added support for all the ts loaders we mentioned in
eslint-ts-patch
and listed their trade-offs, where you can give them a try today.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@privatenumber I tried to use tsx
tsImport
as explained here to load a.ts
config file, but didn't succeed. This is my code:where
fileURL
is the URL of this config file:The error stack trace indicates that the config file is being loaded as CommonJS:
I guess I'm doing something wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not the best place to discuss this. Can you send me a reproduction link in the tsx repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think the problem is that I wasn't calling
register
fromrequire("tsx/cjs/api")
. It works if I add that call beforetsImport
. Another problem is that there is seemingly no way to completely undo the changes done bytsImport
to the Node.js loader internals. Particularly, I think there is no way to unregister the ESMModule
loader. I didn't even find out how to do that programmatically, so this is possibly a limitation of Node.js.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the ts configs, does it check the ts type, or is it just erasure typings?