Skip to content

Conversation

aryaemami59
Copy link
Contributor

@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 an optional peer 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

@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 d5a00f9
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/66b3cf49ad72010009ee7257

@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
@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
Contributor 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
Contributor 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
Contributor 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion cli Relates to ESLint's command-line interface contributor pool core Relates to ESLint's core APIs and features feature This change adds a new feature to ESLint

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.