-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
Worth linking the prior art in this area: #50 |
I think it makes sense and is low cost to support this in a runtime that supports ts natively. Like deno and bun, we can just import them. |
@bradzacher Yes thank you!!! |
|
||
The primary motivation for adding support for TypeScript configuration files to ESLint is to enhance the developer experience and accommodate the evolving JavaScript ecosystem. As TypeScript's popularity continues to grow, more projects are adopting TypeScript not only for their source code but also for their configuration files. This shift is driven by TypeScript's ability to provide compile-time type checks and IntelliSense. By supporting `eslint.config.ts`, `eslint.config.mts`, and `eslint.config.cts`, ESLint will offer first-class support to TypeScript users, allowing them to leverage these benefits directly within their ESLint configuration. | ||
|
||
## Detailed Design |
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
or eslint . -c eslint.config.ts
and they just work. Same as with a eslint.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?
Which version of TypeScript can the config file be written in? With what tsconfig settings? Does this mean eslint would need to depend on typescript, causing it to be installed for non-TS users? if not, then would eslint be able to consume typescript in pnpm and yarn pnp in order to transpile the eslint config? |
- [Reference to the question](eslint#117 (comment))
It's possible to declare an implicit, optional peer dependency in a way that both yarn and pnpm will respect. {
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
},
} You don't even need to declare an explicit peer dependency with this config as it implicitly declares a dep on For context this is how the |
We are going to be using
As far as I know,
I think |
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.
LGTM. Pending re-approval of the latest changes by @nzakas.
|
||
const isTS = isFileTS(filePath) | ||
|
||
if (isTS) { |
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.
We should probably do a simple test to see if Jiti is needed (it's not in Deno or Bun):
if (isTS) { | |
if (isTS && !globalThis.Deno && !globalThis.Bun) { |
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.
Overall, I'm happy with the direction. Let's make sure to note that jiti
, tsx
, or whatever we use, should be an optional dependency that people are required to manually install to use. I think there is still some exploration on implementation to do, but that's fine to do outside of the RFC as the overall approach won't change.
Given that we have two approvals from TSC members, I'm moving this to final commenting.
It's important to note that if a TS-specific tool is a runtime dep, then it's extra weight for non-TS users; and if it's a peer dep, even an optional one, some users may be forced to install it (not every tool considers optionality); and if it's an optional dep, it will always be installed (but if it fails to compile it won't fail the overarching install); and if it's none of those, then it's a hidden dep that users won't know is needed until runtime. In terms of maintainability for eslint, and correctness for users, an optional peer dep is probably the best bet - but, note that adding peer deps, even optional ones, is a breaking change. |
While Jiti would add a little under two MB for users, this is a significantly valuable feature, and adopting it in a way that is a breaking change would mean that it'd have to wait until ESLint 10. If ESLint 9's timeline was not an outlier, that will be quite a long time for users to wait. It may be preferable to add it as a dependency now, and make it a peer dependency for the next major version, so users will only be waiting for that potential 2 MB savings. And, either way, I was under the impression that node_modules size is irrelevant. |
@miscellaneo i don't think your snark is helpful or in line with the CoC. In general it's more that I don't want the ick of TS-related things in a project that doesn't suffer the burden of using TS, but I tried to express that in a way that wouldn't trigger those who love TS. |
Which package managers don't honor And yes, i agree it must remain optional, keep eslint slim please. |
npm: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependenciesmeta Personally, I think this is enough to move forward without a breaking change. But to be extra safe, I guess we should also investigate which versions of these package managers support for |
@privatenumber it's still always a breaking change, because someone who has a version installed that doesn't satisfy the optional range will still get a failed install. Restating, adding a peer dep is always a breaking change, without exception, optional or not, forever. |
@ljharb won't all the package managers either log a warning if it isn't satisfied (not fail the build) or just install the peer dep as specified? I didn't realise that one of them hard failed if the peer dep wasn't satisfied. If you wanted to avoid any logging etc whilst still satisfying pnp et al constraints then you can just not list the peer dep and only list the optional peer dep. As I mentioned above - that's what we do for the TS dep for ts-eslint. We did that because of the install logs we caused for users who installed us as a transient dependency (specifically for |
They should all fail - a peer del requirement is hoisted and necessary. Optional means it can be absent, not that it can be out of range. |
@bradzacher as i can tell, npm has a other package managers may have a similar config. |
But they don't by default, as @aladdin-add notes. That's not for me to decide as a non-member of eslint. I'd personally say no so long as the current/LTS versions of package managers silently ignore the optional dep (as @privatenumber mentioned above - will require some research to confirm that). |
That’s not what that config is for - that’s to disable npm’s attempt to guess the right version. Im pretty certain a mismatch will always fail. |
We should include testing of the different behaviors of different package managers as part of the implementation before release. My feeling is that adding an optional dependency that isn't installed by default doesn't constitute a breaking change, but it really comes down to the user experience. |
Testing is a great idea. In particular, i believe it’s a breaking change for a user who already has an out of range version of that optional peer dep installed - optional refers to presence, not range compliance. |
One could declare an optional dep on That's what we do on typescript-eslint for the typescript dependency. We do that to allow people to run older or newer TS versions at their own risk with a warning logged (that can be turned off via config). |
Fair point, that would make it pretty defensibly non-breaking. |
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.
The overall approach LGTM. I agree to leave the details like which tool we will use (jiti
, tsx
, or something else that provides the functionality needed for this design) and how we will declare it as a dependency for the implementation phase.
This RFC has been approved. That means implementation can officially begin. @fasttime as you've done a lot of investigation into compatibility of the different approaches, we'll look to you to help guide the implementation to completion. |
FYI node just landed nodejs/node@35f92d9 which enables typescript execution 🎉. |
Thanks for the update. If new versions of Node.js add stable built-in support for TypeScript files, I think we may consider removing the additional logic to support TypeScript configs in a future major release of ESLint. |
It is implemented with an experimental flag, so we'll need to wait until it's stable to consider it. |
Yeah, it's going to be a while until that stabilizes. Maybe for Node 24. |
Summary
Add support for TypeScript config files (
eslint.config.ts
,eslint.config.mts
,eslint.config.cts
).Related Issues
This PR is related to this RFC.