-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Run local eslint rules directly as typescript #2312
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
Conversation
Remove the need to use `tsx`
Matches the version we use in vscode 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.
Pull request overview
This PR attempts to modernize the ESLint plugin architecture by removing the dependency on tsx and directly running TypeScript files using Node.js's experimental TypeScript support. The changes migrate from CommonJS to ES modules, update type assertions to use the as syntax, and leverage modern Node.js features like import.meta.dirname.
Key Changes
- Migrated custom ESLint rules from CommonJS (
export =) to ES modules (export default) - Replaced
.eslintplugin/index.jswith.eslintplugin/index.tsto dynamically load rules using ESM imports - Updated all type assertions from angle-bracket syntax (
<Type>) toas Typesyntax throughout ESLint plugin files
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| eslint.config.mjs | Changed to import TypeScript files directly from .eslintplugin/index.ts instead of compiled JavaScript |
| .eslintplugin/tsconfig.json | Updated to ES2024 target with allowImportingTsExtensions and erasableSyntaxOnly for Node.js TypeScript support |
| .eslintplugin/package.json | Added "type": "module" to enable ES module resolution |
| .eslintplugin/index.ts | New file replacing index.js, uses dynamic imports and import.meta.dirname to load rules |
| .eslintplugin/utils.ts | Updated type assertions from <Type> to as Type syntax |
| .eslintplugin/no-runtime-import.ts | Changed export syntax, updated type assertions, migrated from __dirname to import.meta.dirname, added .ts extension to imports |
| .eslintplugin/*.ts (all rule files) | Consistently changed from export = to export default and updated type assertions to as syntax |
| .eslintplugin/index.js | Deleted - replaced with TypeScript implementation |
| headerEslint.rules.header.meta.schema = false; | ||
|
|
||
| import localEslint from './.eslintplugin/index.js'; | ||
| import * as localEslint from './.eslintplugin/index.ts'; |
Copilot
AI
Dec 2, 2025
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.
Importing .ts files directly in an .mjs file will fail at runtime without additional configuration. Node.js (even version 22.14.0) cannot natively import TypeScript files without either:
- The
--experimental-strip-typesflag, or - A TypeScript loader/transpiler (like
tsxwhich was removed in this PR)
The ESLint CLI will fail to load this config file. You'll need to either:
- Keep the old approach with a
.jsfile that usestsxto load TypeScript files - Compile the
.eslintpluginfiles to JavaScript and import the compiled.jsfiles - Use a different mechanism to load TypeScript-based ESLint rules
Consider adding a build step that compiles .eslintplugin/*.ts to .eslintplugin/dist/*.js and importing from there instead.
| import * as localEslint from './.eslintplugin/index.ts'; | |
| import * as localEslint from './.eslintplugin/dist/index.js'; |
Remove the need to use
tsxhere