Oxlint 配置文件
此配置与 ESLint v8 的配置模式(eslintrc.json)保持一致。
用法:oxlint -c oxlintrc.json --import-plugin
注意
仅支持 .json 格式。您可以在配置文件中使用注释。
示例
.oxlintrc.json
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["import", "typescript", "unicorn"],
"env": {
"browser": true
},
"globals": {
"foo": "readonly"
},
"settings": {
"react": {
"version": "18.2.0"
},
"custom": {
"option": true
}
},
"rules": {
"eqeqeq": "warn",
"import/no-cycle": "error",
"react/self-closing-comp": [
"error",
{
"html": false
}
]
},
"overrides": [
{
"files": ["*.test.ts", "*.spec.ts"],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
]
}$schema
type: string
用于编辑器工具的模式 URI。
categories
type: object
一次性配置整个规则类别。
通过这种方式启用或禁用的规则将被 rules 字段中的个别规则覆盖。
示例
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"categories": {
"correctness": "warn"
},
"rules": {
"eslint/no-unused-vars": "error"
}
}categories.correctness
categories.nursery
categories.pedantic
categories.perf
categories.restriction
categories.style
categories.suspicious
env
type: Record<string, boolean>
预定义全局变量。
环境指定哪些全局变量是预定义的。 有关可用环境及其提供的内容,请参阅 ESLint 的环境列表。
extends
type: string[]
此配置文件所扩展(继承)的配置文件路径。这些文件相对于包含 extends 属性的配置文件位置进行解析。配置文件从第一个到最后一个合并,最后一个文件会覆盖前面的文件。
globals
type: Record<string, string>
添加或移除全局变量。
对于每个全局变量,将其值设置为 "writable" 可允许该变量被重新赋值,设置为 "readonly" 则禁止重新赋值。
可以通过将值设为 "off" 来禁用全局变量。例如,在大多数 Es2015 全局变量可用但 Promise 不可用的环境中,可以使用以下配置:
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"env": {
"es6": true
},
"globals": {
"Promise": "off"
}
}您也可以使用 "readable" 或 false 表示 "readonly",使用 "writeable" 或 true 表示 "writable"。
ignorePatterns
type: string[]
default: []
在检查期间忽略的通配符模式。这些通配符从配置文件路径解析。
jsPlugins
type: array
JS 插件,允许在 Oxlint 中使用 ESLint 插件。
有关 JS 插件的更多信息,请参阅 文档。
注意:JS 插件为实验性功能,不受 semver 约束。
示例:
基本用法,使用本地插件路径。
{
"jsPlugins": ["./custom-plugin.js"],
"rules": {
"custom/rule-name": "warn"
}
}通过为同名的 JS 插件提供别名,同时使用内置的 Rust 插件和相同名称的 JS 插件。
{
"plugins": ["import"],
"jsPlugins": [{ "name": "import-js", "specifier": "eslint-plugin-import" }],
"rules": {
"import/no-cycle": "error",
"import-js/no-unresolved": "warn"
}
}jsPlugins[n]
type: object | string
jsPlugins[n].name
type: string
插件的自定义名称/别名。
注意:以下插件名称已被保留,因为它们在 Oxlint 内部以 Rust 原生实现,不能用于 JS 插件:
- react(包含 react-hooks)
- unicorn
- typescript(包含 @typescript-eslint)
- oxc
- import(包含 import-x)
- jsdoc
- jest
- vitest
- jsx-a11y
- nextjs
- react-perf
- promise
- node
- vue
- eslint
如果您需要使用其中任意插件的 JavaScript 版本,请提供自定义别名以避免冲突。
jsPlugins[n].specifier
type: string
插件的路径或包名称
overrides
type: array
overrides[n]
type: object
overrides[n].env
type: object
环境启用或禁用一组全局变量。
overrides[n].files
type: string[]
一组 glob 模式。
overrides[n].globals
type: object
启用或禁用特定的全局变量。
overrides[n].jsPlugins
type: array
此覆盖项的 JS 插件,允许在 Oxlint 中使用 ESLint 插件。
有关 JS 插件的更多信息,请参阅 文档。
注意:JS 插件为实验性功能,不受 semver 约束。
overrides[n].jsPlugins[n]
type: object | string
overrides[n].jsPlugins[n].name
type: string
插件的自定义名称/别名。
注意:以下插件名称已被保留,因为它们在 Oxlint 内部以 Rust 原生实现,不能用于 JS 插件:
- react(包含 react-hooks)
- unicorn
- typescript(包含 @typescript-eslint)
- oxc
- import(包含 import-x)
- jsdoc
- jest
- vitest
- jsx-a11y
- nextjs
- react-perf
- promise
- node
- vue
- eslint
如果您需要使用其中任意插件的 JavaScript 版本,请提供自定义别名以避免冲突。
overrides[n].jsPlugins[n].specifier
type: string
插件的路径或包名称
overrides[n].plugins
type: array
default: null
可选地更改此覆盖项启用的插件。当省略时,使用基础配置的插件。
overrides[n].plugins[n]
type: "eslint" | "react" | "unicorn" | "typescript" | "oxc" | "import" | "jsdoc" | "jest" | "vitest" | "jsx-a11y" | "nextjs" | "react-perf" | "promise" | "node" | "vue"
overrides[n].rules
type: object
请参阅 Oxlint 规则
plugins
type: array
default: null
Oxlint 启用的内置插件。 您可以查看网站上列出的可用插件 网页。
注意:设置 plugins 字段将覆盖基础插件集。 plugins 数组应反映您希望使用的所有插件。
plugins[n]
type: "eslint" | "react" | "unicorn" | "typescript" | "oxc" | "import" | "jsdoc" | "jest" | "vitest" | "jsx-a11y" | "nextjs" | "react-perf" | "promise" | "node" | "vue"
rules
type: object
请参阅 Oxlint 规则
settings
type: object
配置检查器插件的行为。
以下是在 monorepo 中使用 Next.js 时的示例:
{
"settings": {
"next": {
"rootDir": "apps/dashboard/"
},
"react": {
"linkComponents": [
{
"name": "Link",
"linkAttribute": "to"
}
]
},
"jsx-a11y": {
"components": {
"Link": "a",
"Button": "button"
}
}
}
}settings.jsdoc
type: object
settings.jsdoc.augmentsExtendsReplacesDocs
type: boolean
default: false
仅适用于 require-(yields|returns|description|example|param|throws) 规则
settings.jsdoc.exemptDestructuredRootsFromChecks
type: boolean
default: false
仅适用于 require-param-type 和 require-param-description 规则
settings.jsdoc.ignoreInternal
type: boolean
default: false
适用于所有规则,但不适用于 empty-tags 规则
settings.jsdoc.ignorePrivate
type: boolean
default: false
适用于所有规则,但不适用于 check-access 和 empty-tags 规则
settings.jsdoc.ignoreReplacesDocs
type: boolean
default: true
仅适用于 require-(yields|returns|description|example|param|throws) 规则
settings.jsdoc.implementsReplacesDocs
type: boolean
default: false
仅适用于 require-(yields|returns|description|example|param|throws) 规则
settings.jsdoc.overrideReplacesDocs
type: boolean
default: true
仅适用于 require-(yields|returns|description|example|param|throws) 规则
settings.jsdoc.tagNamePreference
type: object
default: {}
settings.jsx-a11y
type: object
配置 JSX A11y 插件规则。
请参阅 eslint-plugin-jsx-a11y 的 配置文档以获取完整参考。
settings.jsx-a11y.attributes
type: Record<string, array>
default: {}
属性名称到其对应 DOM 属性的映射。 这对使用不同属性名称的非 React 框架非常有用。
示例:
{
"settings": {
"jsx-a11y": {
"attributes": {
"for": ["htmlFor", "for"]
}
}
}
}settings.jsx-a11y.components
type: Record<string, string>
default: {}
为了让您的自定义组件被视为 DOM 元素,您可以提供组件名称到 DOM 元素名称的映射。
示例:
{
"settings": {
"jsx-a11y": {
"components": {
"Link": "a",
"IconButton": "button"
}
}
}
}settings.jsx-a11y.polymorphicPropName
type: string
一个可选设置,用于定义代码中用于创建多态组件的属性。 此设置将用于确定需要语义上下文的规则中的元素类型。
例如,如果将 polymorphicPropName 设置为 as,则这个元素:
<Box as="h3">Hello</Box>将被视为 h3。如果没有设置,则该组件将被视为 Box。
settings.next
type: object
配置 Next.js 插件规则。
settings.next.rootDir
type: array | string
settings.next.rootDir[n]
type: string
settings.react
type: object
配置 React 插件规则。
settings.react.componentWrapperFunctions
type: string[]
default: []
包裹 React 组件并应被视为高阶组件(HOC)的函数。
示例:
{
"settings": {
"react": {
"componentWrapperFunctions": ["observer", "withRouter"],
},
},
}settings.react.formComponents
type: array
default: []
作为 <form> 替代方案使用的表单组件,如 <Formik>。
示例:
{
"settings": {
"react": {
"formComponents": [
"CustomForm",
// OtherForm 被视为表单组件并具有 endpoint 属性
{ "name": "OtherForm", "formAttribute": "endpoint" },
// 如有必要,可指定多个属性
{ "name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"] },
],
},
},
}settings.react.formComponents[n]
type: object | string
settings.react.formComponents[n].attribute
type: string
settings.react.formComponents[n].name
type: string
settings.react.linkComponents
type: array
default: []
作为 <a> 替代方案使用的链接组件,如 <Link>。
示例:
{
"settings": {
"react": {
"linkComponents": [
"HyperLink",
// 对于使用不同于 `href` 的属性名的组件,使用 `linkAttribute`
{ "name": "MyLink", "linkAttribute": "to" },
// 如有必要,可指定多个属性
{ "name": "Link", "linkAttribute": ["to", "href"] },
],
},
},
}settings.react.linkComponents[n]
type: object | string
settings.react.linkComponents[n].attribute
type: string
settings.react.linkComponents[n].name
type: string
settings.react.version
type: string
default: null
用于版本相关规则的 React 版本。
接受 semver 版本(例如 "18.2.0"、"17.0")。
示例:
{
"settings": {
"react": {
"version": "18.2.0",
},
},
}settings.vitest
type: object
配置 Vitest 插件规则。
请参阅 eslint-plugin-vitest 的 配置文档以获取完整参考。
settings.vitest.typecheck
type: boolean
default: false
是否为 Vitest 规则启用类型检查模式。 启用后,某些规则将跳过对 describe 块的特定检查, 以适应 TypeScript 类型检查场景。
