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

feat: Add support for TS config files #18134

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

aryaemami59
Copy link

@aryaemami59 aryaemami59 commented Feb 21, 2024

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[X] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

This PR:

  • Adds support for TypeScript config files (eslint.config.ts, eslint.config.mts, eslint.config.cts)
  • Adds jiti as a dependency.
  • Conditionally imports jiti based on whether the config file's extension ends with ts.

I went through a lot of different possible ways of implementing it, and this by far seems to be the simplest way of doing it without changing too much of the internals of the package or adding too many dependencies.

Is there anything you'd like reviewers to focus on?

@eslint-github-bot
Copy link

Hi @aryaemami59!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

Copy link

linux-foundation-easycla bot commented Feb 21, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added cli Relates to ESLint's command-line interface core Relates to ESLint's core APIs and features labels Feb 21, 2024
Copy link

netlify bot commented Feb 21, 2024

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit dad7b0e
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/66310b02216c0f0007d570d8

@aryaemami59 aryaemami59 changed the title Add support for TypeScript config files (eslint.config.ts, eslint.config.mts, eslint.config.cts) feat: Add support for TypeScript config files (eslint.config.ts, eslint.config.mts, eslint.config.cts) Feb 21, 2024
@eslint-github-bot
Copy link

Hi @aryaemami59!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@aryaemami59 aryaemami59 changed the title feat: Add support for TypeScript config files (eslint.config.ts, eslint.config.mts, eslint.config.cts) feat: Add support for TS config files Feb 21, 2024
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Feb 21, 2024
lib/eslint/eslint.js Outdated Show resolved Hide resolved
lib/eslint/eslint.js Outdated Show resolved Hide resolved
lib/eslint/eslint.js Outdated Show resolved Hide resolved
@cany748
Copy link

cany748 commented Feb 29, 2024

Wouldn't it be better to use Jiti for this? I think it's perfect for this, it's used in Nuxt and TailwindCSS to load configuration from Typescript files. It is much smaller and faster than Typescript.

@aladdin-add
Copy link
Member

aladdin-add commented Mar 4, 2024

the first-class ts config support has been discussed in #12078 eslint/rfcs#50, and seems we didn't come to an agreement to accept it.

@aladdin-add
Copy link
Member

it should be possible to use ts config in the current config. The easiest way I can think of is to use --config and --loader, something like:

NODE_OPTIONS=--loader=tsx eslint --config=eslint.config.ts xxx

@aryaemami59
Copy link
Author

@cany748 I had to research it to make sure it doesn't create import side effects. But it seems like you were right, it does what I wanted tsx to do without creating side effects.

@aryaemami59
Copy link
Author

@aladdin-add

it should be possible to use ts config in the current config. The easiest way I can think of is to use --config and --loader, something like:

NODE_OPTIONS=--loader=tsx eslint --config=eslint.config.ts xxx

That doesn't work you'll get:

Error: tsx must be loaded with --import instead of --loader

And if you use

NODE_OPTIONS=--import=tsx eslint --config=eslint.config.ts

you'll get a YAMLException error if you have a type annotation anywhere in the config file. And if you don't have a type annotation anywhere you'll still get this error:

Error: ESLint configuration in --config is invalid:
        - Property "" is the wrong type

@aladdin-add
Copy link
Member

I mean flat config (which is the default in eslint v9). If you are using eslint v8, the default is eslintrc, and you need to specify ESLINT_USE_FLAT_CONFIG=true

@aryaemami59
Copy link
Author

@aladdin-add

I mean flat config (which is the default in eslint v9). If you are using eslint v8, the default is eslintrc, and you need to specify ESLINT_USE_FLAT_CONFIG=true

That still won't work with .mts or .cts extensions, it also doesn't respect the type field in package.json.

Out of curiosity what is your opinion in the current solution this PR provides?

@aladdin-add
Copy link
Member

I think it needs a rfc to evaluate: https://github.com/eslint/rfcs

My hope:

  • it's opt-in, not default
  • 0-overhead for js users
  • no bind tsx/ts-node/..., worth exploring a standard way to let users make the choice which one to use.

@nzakas
Copy link
Member

nzakas commented Mar 7, 2024

I agree with @aladdin-add -- I think we're now at the point where it makes sense to put together an RFC discussing the design with the potential alternatives.

@nzakas nzakas added the needs design Important details about this change need to be discussed label Mar 7, 2024
@aryaemami59
Copy link
Author

@nzakas

I agree with @aladdin-add -- I think we're now at the point where it makes sense to put together an RFC discussing the design with the potential alternatives.

Fair enough, I will put up an RFC.

@sam3k
Copy link
Contributor

sam3k commented Mar 12, 2024

Per 2024-03-07 TSC Meeting, we will remove from v9 board for now and wait for an RFC from @aryaemami59

@aryaemami59
Copy link
Author

RFC has been submitted: eslint/rfcs#117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Relates to ESLint's command-line interface core Relates to ESLint's core APIs and features feature This change adds a new feature to ESLint needs design Important details about this change need to be discussed
Projects
Status: RFC Opened
Development

Successfully merging this pull request may close these issues.

None yet

6 participants