eslint-ts-patch
Support loading eslint.config.mjs
or eslint.config.ts
as flat config file for ESLint.
Configure files will be searched in the following order, the first one found will be used:
eslint.config.js
eslint.config.mjs
eslint.config.cjs
eslint.config.ts
eslint.config.mts
eslint.config.cts
For .js
, .cjs
, and .mjs
files, they will be loaded by Node's native import()
.
For .ts
, .cts
, and .mts
files, they will be loaded using jiti
.
Context:
Unfortunately ESLint team decided to not support the detection of..cjs
and.mjs
as flat config- Update: ESLint revised the decision to support
eslint.config.mjs
andeslint.config.cjs
but haven't landed yet
Install
npm i -D eslint-ts-patch eslint@npm:eslint-ts-patch
It should make your eslint
CLI work for those config files automatically. If it's still not, you can try switching the CLI to eslint-ts
.
Compatibility
Tested with the following tools:
Package Managers
npm
βpnpm
βyarn
β
Integrations
eslint
CLI β- VSCode ESLint extension β
(as it's executing your local
node_modules/.bin/eslint
)
Haven't gotten chance to test with other integrations, contributions are welcome.
Versioning
This package proxies all ESLint exports, it should be compatible by aliasing the eslint
package. The version of this package is the same as the latest supported ESLint version in addition to a patch number suffix indicating the patches of this package (e.g. 8.55.0-1
). It's using ^
relaxed dependency of eslint
, so it should work with any newer versions of ESLint.
How it works
As the support of eslint.config.js
seems to be quite hard-coded in ESLint, this package proxies all exports of ESLint and installs this register beforehand. The register will swap some internal code of ESLint at runtime to make it work.
Disclaimer
It's only recommended to install this as top-level development dependency (user-aware). For plugin and library authors, it's ok to document the usage of this package for better DX. But we suggest avoiding having this as the dependency of your library or plugin, otherwise, take your own risk.
Troubleshooting
Is the Patch Working
This patch is designed to be as transparent as possible. If you want to verify if it's working, you can add DEBUG="eslint-ts-patch"
environment variable to your command to see the debug logs.
β DEBUG="eslint-ts-patch" npx eslint -v
eslint-ts-patch initialized +0ms
eslint-ts-patch patched lib/eslint/flat-eslint.js +59ms
v8.55.0
Sponsors
License
MIT License Β© 2023-PRESENT Anthony Fu