JS 插件
Oxlint 支持用 JS 编写的插件——无论是自定义编写的,还是来自 npm 的。
Oxlint 的插件 API 与 ESLint v9+ 兼容,因此大多数现有的 ESLint 插件应该可以在 Oxlint 中开箱即用。
几乎整个 ESLint 插件 API 现已实现(见 下方),因此大多数现有的 ESLint 插件应该可以开箱即用。
使用 JS 插件
- 在
.oxlintrc.json配置文件的jsPlugins下添加插件路径。 - 在
rules下添加来自插件的规则。
路径可以是任何有效的导入说明符,例如 ./plugin.js、eslint-plugin-foo 或 @foo/eslint-plugin。 路径是相对于配置文件本身解析的。
jsonc
{
"jsPlugins": ["./path/to/my-plugin.js", "eslint-plugin-whatever", "@foobar/eslint-plugin"],
"rules": {
"my-plugin/rule1": "error",
"my-plugin/rule2": "warn",
"whatever/rule1": "error",
"whatever/rule2": "warn",
"@foobar/rule1": "error",
},
// ... 其他配置 ...
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
jsPlugins: ["./path/to/my-plugin.js", "eslint-plugin-whatever", "@foobar/eslint-plugin"],
rules: {
"my-plugin/rule1": "error",
"my-plugin/rule2": "warn",
"whatever/rule1": "error",
"whatever/rule2": "warn",
"@foobar/rule1": "error",
},
// ... 其他配置 ...
});插件别名
您还可以为插件定义不同的名称(别名)。这在以下情况下很有用:
- 默认插件名称与原生 Oxlint 插件的名称冲突(例如 jsdoc、react 等)。
- 默认插件名称非常长。
- 您想使用 Oxlint 原生支持的插件,但您需要的特定规则尚未在 Oxlint 的原生版本中实现。
jsonc
{
"jsPlugins": [
// `jsdoc` 是保留名称,因为 Oxlint 原生支持它
{
"name": "jsdoc-js",
"specifier": "eslint-plugin-jsdoc",
},
// 缩短名称
{
"name": "short",
"specifier": "eslint-plugin-with-name-so-very-very-long",
},
// 将不想别名的插件仅列为说明符
"eslint-plugin-whatever",
],
"rules": {
"jsdoc-js/check-alignment": "error",
"short/rule1": "error",
"whatever/rule2": "error",
},
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
jsPlugins: [
// `jsdoc` 是保留名称,因为 Oxlint 原生支持它
{
name: "jsdoc-js",
specifier: "eslint-plugin-jsdoc",
},
// 缩短名称
{
name: "short",
specifier: "eslint-plugin-with-name-so-very-very-long",
},
// 将不想别名的插件仅列为说明符
"eslint-plugin-whatever",
],
rules: {
"jsdoc-js/check-alignment": "error",
"short/rule1": "error",
"whatever/rule2": "error",
},
});请参阅 编写 JS 插件 页面,了解如何为 Oxlint 编写自己的 JS 插件和自定义规则。
已知支持的 ESLint 插件
我们对许多流行的 ESLint 插件运行一致性测试,以确保它们能与 Oxlint 一起工作。这些包括:
eslint-plugin-cypress(一致性测试结果)@e18e/eslint-plugin(一致性测试结果)eslint-plugin-mocha(一致性测试结果)eslint-plugin-playwright(一致性测试结果)eslint-plugin-react-hooks(一致性测试结果): 请注意,其中一些规则已在 Oxlint 中原生支持,因此通常应使用这些原生规则eslint-plugin-regexp(一致性测试结果)eslint-plugin-sonarjs(一致性测试结果)eslint-plugin-storybook(一致性测试结果)@stylistic/eslint-plugin(一致性测试结果)eslint-plugin-testing-library(一致性测试结果)
请注意,上述列表并非详尽无遗,许多 其他 ESLint 插件也能与 Oxlint 一起工作。这些只是我们明确测试过的一些流行插件。
您可以在 GitHub 讨论 中查看更多关于已知能与 Oxlint 一起工作的插件的信息。
API 支持
Oxlint 支持几乎所有的 ESLint API 表面:
- AST 遍历。
- AST 探索(
node.parent、context.sourceCode.getAncestors)。 - 修复。
- 规则选项。
- 选择器(ESLint 文档)。
SourceCodeAPI(例如context.sourceCode.getText(node))。SourceCodetokens API(例如context.sourceCode.getTokens(node))。- 作用域分析。
- 控制流分析(代码路径)。
- 内联禁用指令。(
// oxlint-disable) - 语言服务器(IDE)支持 + 建议(编辑器内诊断和快速修复)
尚未支持:
- 自定义文件格式和解析器(例如 Svelte、Vue、Angular)。
- 依赖 TypeScript 类型感知的 lint 规则。
在 ESLint v9 或更早版本中被移除的 ESLint API 在大多数情况下将不会被实现。如果某个 ESLint 插件无人维护且从未更新以升级其 API 用法以适应 ESLint v9,您可能需要自己修改该插件或寻找替代方案。
我们将在未来几个月内实现剩余功能,旨在支持 100% 的 ESLint 插件 API 表面。
