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",
},
});有关为 Oxlint 编写自己的 JS 插件和自定义规则的信息,请参阅编写 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 Discussion 中查看已知可在 Oxlint 中使用的插件的更多信息。
API 支持
Oxlint 支持几乎所有的 ESLint API:
- AST 遍历。
- AST 探索(
node.parent、context.sourceCode.getAncestors)。 - 修复。
- 规则选项。
- 选择器(ESLint 文档)。
SourceCodeAPI(例如context.sourceCode.getText(node))。SourceCodetoken API(例如context.sourceCode.getTokens(node))。- 作用域分析。
- 控制流分析(代码路径)。
- 内联禁用指令。(
// oxlint-disable) - 语言服务器(IDE)支持 + 建议(编辑器内诊断和快速修复)
尚不支持:
- 自定义文件格式和解析器(例如 Svelte、Vue、Angular)。
- 依赖 TypeScript 类型感知的 lint 规则。
在 ESLint v9 或更早版本中被移除的 ESLint API 在大多数情况下不会实现。如果某个 ESLint 插件无人维护且从未更新以升级其 ESLint v9 的 API 使用,您可能需要自己修改插件或寻找替代方案。
我们将在未来几个月内实现剩余功能,目标是支持 100% 的 ESLint 插件 API。