migrate-oxlint
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThis skill guides you through migrating a JavaScript/TypeScript project from ESLint to Oxlint.
本技能将指导你如何将JavaScript/TypeScript项目从ESLint迁移到Oxlint。
Overview
概述
Oxlint is a high-performance linter that implements many popular ESLint rules natively in Rust. It can be used alongside ESLint or as a full replacement.
An official migration tool is available:
@oxlint/migrateOxlint是一款高性能代码检查工具,它采用Rust原生实现了众多流行的ESLint规则,既可以和ESLint搭配使用,也可以完全替代ESLint。
官方提供了迁移工具:
@oxlint/migrateStep 1: Run Automated Migration
步骤1:运行自动迁移
Run the migration tool in the project root:
bash
npx @oxlint/migrateThis reads your ESLint flat config and generates a file.
.oxlintrc.json在项目根目录下运行迁移工具:
bash
npx @oxlint/migrate该工具会读取你的ESLint flat配置,生成文件。
.oxlintrc.jsonKey Options
核心选项
| Option | Description |
|---|---|
| Merge with an existing |
| Include type-aware rules (requires running oxlint with |
| Include experimental rules still under development |
| Enable/disable ESLint plugin migration via |
| List rules that could not be migrated |
| Convert |
| Specify output path (default: |
If your ESLint config is not at the default location, pass the path explicitly:
bash
npx @oxlint/migrate ./path/to/eslint.config.js| 选项 | 说明 |
|---|---|
| 与已有的 |
| 包含类型感知规则(需要搭配 |
| 包含仍在开发中的实验性规则 |
| 通过 |
| 列出无法完成迁移的规则 |
| 将 |
| 指定输出路径(默认: |
如果你的ESLint配置不在默认位置,请显式传入路径:
bash
npx @oxlint/migrate ./path/to/eslint.config.jsStep 2: Review Generated Config
步骤2:检查生成的配置
After migration, review the generated .
.oxlintrc.json迁移完成后,检查生成的文件。
.oxlintrc.jsonPlugin Mapping
插件映射
The migration tool automatically maps ESLint plugins to oxlint's built-in equivalents. The following table is for reference when reviewing the generated config:
| ESLint Plugin | Oxlint Plugin Name |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Default plugins (enabled when field is omitted): , , .
Setting the array explicitly overrides these defaults.
pluginsunicorntypescriptoxcplugins迁移工具会自动将ESLint插件映射为oxlint内置的对应插件。下表可供你检查生成的配置时参考:
| ESLint插件 | Oxlint插件名称 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
默认插件(省略字段时自动启用):、、。
显式设置数组会覆盖这些默认值。
pluginsunicorntypescriptoxcpluginsRule Categories
规则分类
Oxlint groups rules into categories for bulk configuration:
json
{
"categories": {
"correctness": "warn",
"suspicious": "warn"
}
}Available categories: (default: enabled), , , , , , .
correctnesssuspiciouspedanticperfstylerestrictionnurseryIndividual rule settings in override category settings.
rulesOxlint将规则归类到不同分类中,方便批量配置:
json
{
"categories": {
"correctness": "warn",
"suspicious": "warn"
}
}可用分类:(默认:启用)、、、、、、。
correctnesssuspiciouspedanticperfstylerestrictionnurseryrulesCheck Unmigrated Rules
检查未迁移的规则
Run with to see which ESLint rules could not be migrated:
--detailsbash
npx @oxlint/migrate --detailsReview the output and decide whether to keep ESLint for those rules or find oxlint alternatives.
添加参数运行可以查看哪些ESLint规则无法迁移:
--detailsbash
npx @oxlint/migrate --details检查输出结果,决定是否为这些规则保留ESLint,或者寻找oxlint的替代方案。
Step 3: Handle Unsupported Features
步骤3:处理不支持的特性
Some features require manual attention:
- Local plugins (relative path imports): Must be migrated manually to
jsPlugins - : Not supported. Use oxfmt instead
eslint-plugin-prettier - in override configs: Oxlint does not support
settingsinsidesettingsblocksoverrides - ESLint v9+ plugins: Not all work with oxlint's JS Plugins API. Test with
--js-plugins
部分特性需要手动处理:
- 本地插件(相对路径导入):必须手动迁移到
jsPlugins - :不支持,请改用oxfmt
eslint-plugin-prettier - 覆盖配置中的:Oxlint不支持
settings块内的overrides配置settings - ESLint v9+插件:并非所有都兼容oxlint的JS插件API,可以使用参数测试
--js-plugins
External ESLint Plugins
外部ESLint插件
For ESLint plugins without a built-in oxlint equivalent, use the field to load them:
jsPluginsjson
{
"jsPlugins": ["eslint-plugin-custom"],
"rules": {
"custom/my-rule": "warn"
}
}对于没有内置oxlint对应实现的ESLint插件,可以使用字段加载:
jsPluginsjson
{
"jsPlugins": ["eslint-plugin-custom"],
"rules": {
"custom/my-rule": "warn"
}
}Step 4: Update CI and Scripts
步骤4:更新CI和脚本
Replace ESLint commands with oxlint. Path arguments are optional; oxlint defaults to the current working directory.
bash
undefined将ESLint命令替换为oxlint。路径参数是可选的,oxlint默认扫描当前工作目录。
bash
undefinedBefore
迁移前
npx eslint src/
npx eslint --fix src/
npx eslint src/
npx eslint --fix src/
After
迁移后
npx oxlint@latest
npx oxlint@latest --fix
undefinednpx oxlint@latest
npx oxlint@latest --fix
undefinedCommon CLI Options
常用CLI选项对比
| ESLint | oxlint |
|---|---|
| |
| |
| |
| |
| |
| |
Additional oxlint options:
- : Enable rules requiring TypeScript type information
--type-aware - : Specify tsconfig.json path for type-aware linting
--tsconfig <path>
| ESLint | oxlint |
|---|---|
| |
| |
| |
| |
| |
| |
oxlint的额外选项:
- :启用需要TypeScript类型信息的规则
--type-aware - :为类型感知检查指定tsconfig.json路径
--tsconfig <path>
Tips
小贴士
- Start gradually: Enable rules first (the default), then progressively add
correctness,suspicious, etc.pedantic - Run alongside ESLint: Oxlint is designed to complement ESLint during migration. You can run both until all rules are covered.
- Disable comments work: and
// eslint-disablecomments are supported by oxlint. Use// eslint-disable-next-lineto convert them to--replace-eslint-commentsif desired.// oxlint-disable - List available rules: Run to see all supported rules.
npx oxlint@latest --rules - Schema support: Add to
"$schema": "./node_modules/oxlint/configuration_schema.json"for editor autocompletion..oxlintrc.json - Output formats: ,
default,stylish,json,github,gitlab,junit,checkstyleunix
- 逐步迁移:先启用规则(默认开启),再逐步添加
correctness、suspicious等分类的规则pedantic - 可与ESLint并行运行:Oxlint设计为在迁移期间可以和ESLint互补使用,你可以同时运行两者,直到所有规则都完成覆盖
- 禁用注释兼容:oxlint支持和
// eslint-disable注释,如果你需要的话可以使用// eslint-disable-next-line参数将它们转换为--replace-eslint-comments// oxlint-disable - 查看可用规则:运行可以查看所有支持的规则
npx oxlint@latest --rules - 配置Schema支持:在中添加
.oxlintrc.json可以获得编辑器自动补全能力"$schema": "./node_modules/oxlint/configuration_schema.json" - 输出格式:支持、
default、stylish、json、github、gitlab、junit、checkstyleunix