Oxlint 配置文件
🌐 Oxlint Configuration File
此配置与 ESLint v8 的配置架构(eslintrc.json)一致。
🌐 This configuration is aligned with ESLint v8's configuration schema (eslintrc.json).
用法:oxlint -c oxlintrc.json --import-plugin
🌐 Usage: oxlint -c oxlintrc.json --import-plugin
注意
仅支持 .json 格式。你可以在配置文件中使用注释。
🌐 Only the .json format is supported. You can use comments in configuration files.
示例
🌐 Example
.oxlintrc.json
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["import", "typescript", "unicorn"],
"env": {
"browser": true
},
"globals": {
"foo": "readonly"
},
"settings": {},
"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
类型:string
🌐 type: string
编辑器工具的模式 URI。
🌐 Schema URI for editor tooling.
类别
🌐 categories
类型:object
🌐 type: object
一次配置整类规则。
🌐 Configure an entire category of rules all at once.
以这种方式启用或禁用的规则将被 rules 字段中的单独规则覆盖。
🌐 Rules enabled or disabled this way will be overwritten by individual rules in the rules field.
示例
🌐 Example
{
"$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
类型:Record<string, boolean>
🌐 type: Record<string, boolean>
预定义全局变量。
🌐 Predefine global variables.
环境指定了哪些全局变量是预定义的。请参阅 ESLint 的环境列表 了解可用的环境及每个环境所提供的内容。
🌐 Environments specify what global variables are predefined. See ESLint's list of environments for what environments are available and what each one provides.
扩展
🌐 extends
类型:string[]
🌐 type: string[]
此配置文件所扩展(继承)的配置文件路径。文件的解析是相对于包含 extends 属性的配置文件的位置进行的。配置文件从第一个到最后一个进行合并,最后一个文件会覆盖前面的文件。
🌐 Paths of configuration files that this configuration file extends (inherits from). The files are resolved relative to the location of the configuration file that contains the extends property. The configuration files are merged from the first to the last, with the last file overriding the previous ones.
全局变量
🌐 globals
类型:Record<string, string>
🌐 type: Record<string, string>
添加或删除全局变量。
🌐 Add or remove global variables.
对于每个全局变量,将相应的值设置为 "writable" 以允许覆盖该变量,或设置为 "readonly" 以禁止覆盖。
🌐 For each global variable, set the corresponding value equal to "writable" to allow the variable to be overwritten or "readonly" to disallow overwriting.
可以通过将全局变量的值设置为 "off" 来禁用它们。例如,在大多数 Es2015 全局变量可用但 Promise 不可用的环境中,你可以使用如下配置:
🌐 Globals can be disabled by setting their value to "off". For example, in an environment where most Es2015 globals are available but Promise is unavailable, you might use this config:
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"env": {
"es6": true
},
"globals": {
"Promise": "off"
}
}你也可以使用 "readable" 或 false 来表示 "readonly",以及使用 "writeable" 或 true 来表示 "writable"。
🌐 You may also use "readable" or false to represent "readonly", and "writeable" or true to represent "writable".
ignorePatterns
类型:string[]
🌐 type: string[]
默认:[]
🌐 default: []
在代码检查过程中要忽略的通配符。这些通配符是从配置文件路径解析的。
🌐 Globs to ignore during linting. These are resolved from the configuration file path.
jsPlugins
类型:array
🌐 type: array
JS 插件,允许在 Oxlint 中使用 ESLint 插件。
🌐 JS plugins, allows usage of ESLint plugins with Oxlint.
在文档中阅读有关 JS 插件的更多信息。
🌐 Read more about JS plugins in the docs.
注意:JS 插件是实验性的,不遵循语义化版本控制。目前它们不被语言服务器(因此也不被编辑器集成)支持。
🌐 Note: JS plugins are experimental and not subject to semver. They are not supported in the language server (and thus editor integrations) at present.
jsPlugins[n]
类型:object | string
🌐 type: object | string
jsPlugins[n].name
类型:string
🌐 type: string
插件的自定义名称/别名。
🌐 Custom name/alias for the plugin.
注意:以下插件名称是保留的,因为它们在 oxlint 中已用 Rust 原生实现,不能用于 JS 插件:
🌐 Note: The following plugin names are reserved because they are implemented natively in Rust within oxlint and cannot be used for JS plugins:
- React(包括 React Hooks)
- 独角兽
- TypeScript(包括 @typescript-eslint)
- oxc
- 导入 (包括 import-x)
- jsdoc
- jest
- vitest
- jsx-a11y
- Next.js
- react-性能
- 承诺
- 节点
- 视图
- ESLint
如果你需要使用这些插件中的任何一个的 JavaScript 版本,请提供自定义别名以避免冲突。
🌐 If you need to use the JavaScript version of any of these plugins, provide a custom alias to avoid conflicts.
jsPlugins[n].specifier
类型:string
🌐 type: string
插件的路径或包名称
🌐 Path or package name of the plugin
覆盖
🌐 overrides
类型:array
🌐 type: array
覆盖[n]
🌐 overrides[n]
类型:object
🌐 type: object
overrides[n].env
类型:object
🌐 type: object
环境可以启用或禁用一组全局变量。
🌐 Environments enable and disable collections of global variables.
overrides[n].files
类型:string[]
🌐 type: string[]
一组全局匹配模式。
🌐 A set of glob patterns.
overrides[n].globals
类型:object
🌐 type: object
启用或禁用特定的全局变量。
🌐 Enabled or disabled specific global variables.
overrides[n].jsPlugins
类型:array
🌐 type: array
这个覆盖的 JS 插件,允许在 Oxlint 中使用 ESLint 插件。
🌐 JS plugins for this override, allows usage of ESLint plugins with Oxlint.
在文档中阅读有关 JS 插件的更多信息。
🌐 Read more about JS plugins in the docs.
注意:JS 插件是实验性的,不遵循语义化版本控制。目前它们不被语言服务器(因此也不被编辑器集成)支持。
🌐 Note: JS plugins are experimental and not subject to semver. They are not supported in the language server (and thus editor integrations) at present.
overrides[n].jsPlugins[n]
类型:object | string
🌐 type: object | string
overrides[n].jsPlugins[n].name
类型:string
🌐 type: string
插件的自定义名称/别名。
🌐 Custom name/alias for the plugin.
注意:以下插件名称是保留的,因为它们在 oxlint 中已用 Rust 原生实现,不能用于 JS 插件:
🌐 Note: The following plugin names are reserved because they are implemented natively in Rust within oxlint and cannot be used for JS plugins:
- React(包括 React Hooks)
- 独角兽
- TypeScript(包括 @typescript-eslint)
- oxc
- 导入 (包括 import-x)
- jsdoc
- jest
- vitest
- jsx-a11y
- Next.js
- react-性能
- 承诺
- 节点
- 视图
- ESLint
如果你需要使用这些插件中的任何一个的 JavaScript 版本,请提供自定义别名以避免冲突。
🌐 If you need to use the JavaScript version of any of these plugins, provide a custom alias to avoid conflicts.
overrides[n].jsPlugins[n].specifier
类型:string
🌐 type: string
插件的路径或包名称
🌐 Path or package name of the plugin
overrides[n].plugins
类型:array
🌐 type: array
默认:null
🌐 default: null
可选择更改此覆盖的启用插件。若省略,则使用基础配置的插件。
🌐 Optionally change what plugins are enabled for this override. When omitted, the base config's plugins are used.
overrides[n].plugins[n]
类型:"eslint" | "react" | "unicorn" | "typescript" | "oxc" | "import" | "jsdoc" | "jest" | "vitest" | "jsx-a11y" | "nextjs" | "react-perf" | "promise" | "node" | "vue"
🌐 type: "eslint" | "react" | "unicorn" | "typescript" | "oxc" | "import" | "jsdoc" | "jest" | "vitest" | "jsx-a11y" | "nextjs" | "react-perf" | "promise" | "node" | "vue"
overrides[n].rules
类型:object
🌐 type: object
查看 Oxlint 规则
🌐 See Oxlint Rules
插件
🌐 plugins
类型:array
🌐 type: array
默认:null
🌐 default: null
为 Oxlint 启用了内置插件。你可以在 网站 上查看可用插件列表。
🌐 Enabled built-in plugins for Oxlint. You can view the list of available plugins on the website.
注意:设置 plugins 字段将覆盖基础插件集合。plugins 数组应包含你想使用的所有插件。
🌐 NOTE: Setting the plugins field will overwrite the base set of plugins. The plugins array should reflect all of the plugins you want to use.
插件[n]
🌐 plugins[n]
类型:"eslint" | "react" | "unicorn" | "typescript" | "oxc" | "import" | "jsdoc" | "jest" | "vitest" | "jsx-a11y" | "nextjs" | "react-perf" | "promise" | "node" | "vue"
🌐 type: "eslint" | "react" | "unicorn" | "typescript" | "oxc" | "import" | "jsdoc" | "jest" | "vitest" | "jsx-a11y" | "nextjs" | "react-perf" | "promise" | "node" | "vue"
规则
🌐 rules
类型:object
🌐 type: object
查看 Oxlint 规则
🌐 See Oxlint Rules
设置
🌐 settings
类型:object
🌐 type: object
配置 linter 插件的行为。
🌐 Configure the behavior of linter plugins.
如果你在单一代码库中使用 Next.js,这里有一个示例:
🌐 Here's an example if you're using Next.js in a monorepo:
{
"settings": {
"next": {
"rootDir": "apps/dashboard/"
},
"react": {
"linkComponents": [
{
"name": "Link",
"linkAttribute": "to"
}
]
},
"jsx-a11y": {
"components": {
"Link": "a",
"Button": "button"
}
}
}
}settings.jsdoc
类型:object
🌐 type: object
settings.jsdoc.augmentsExtendsReplacesDocs
类型:boolean
🌐 type: boolean
默认:false
🌐 default: false
仅适用于 require-(yields|returns|description|example|param|throws) 规则
🌐 Only for require-(yields|returns|description|example|param|throws) rule
settings.jsdoc.exemptDestructuredRootsFromChecks
类型:boolean
🌐 type: boolean
默认:false
🌐 default: false
仅适用于 require-param-type 和 require-param-description 规则
🌐 Only for require-param-type and require-param-description rule
settings.jsdoc.ignoreInternal
类型:boolean
🌐 type: boolean
默认:false
🌐 default: false
适用于所有规则,但不适用于 empty-tags 规则
🌐 For all rules but NOT apply to empty-tags rule
settings.jsdoc.ignorePrivate
类型:boolean
🌐 type: boolean
默认:false
🌐 default: false
适用于所有规则,但不适用于 check-access 和 empty-tags 规则
🌐 For all rules but NOT apply to check-access and empty-tags rule
settings.jsdoc.ignoreReplacesDocs
类型:boolean
🌐 type: boolean
默认:true
🌐 default: true
仅适用于 require-(yields|returns|description|example|param|throws) 规则
🌐 Only for require-(yields|returns|description|example|param|throws) rule
settings.jsdoc.implementsReplacesDocs
类型:boolean
🌐 type: boolean
默认:false
🌐 default: false
仅适用于 require-(yields|returns|description|example|param|throws) 规则
🌐 Only for require-(yields|returns|description|example|param|throws) rule
settings.jsdoc.overrideReplacesDocs
类型:boolean
🌐 type: boolean
默认:true
🌐 default: true
仅适用于 require-(yields|returns|description|example|param|throws) 规则
🌐 Only for require-(yields|returns|description|example|param|throws) rule
settings.jsdoc.tagNamePreference
类型:object
🌐 type: object
默认:{}
🌐 default: {}
settings.jsx-a11y
类型:object
🌐 type: object
配置 JSX A11y 插件规则。
🌐 Configure JSX A11y plugin rules.
请参阅 eslint-plugin-jsx-a11y 的配置,以获取完整参考。
🌐 See eslint-plugin-jsx-a11y's configuration for a full reference.
settings.jsx-a11y.attributes
类型:Record<string, array>
🌐 type: Record<string, array>
默认:{}
🌐 default: {}
属性名称与其 DOM 等效项的映射。 这对于使用不同属性名称的非 React 框架非常有用。
🌐 Map of attribute names to their DOM equivalents. This is useful for non-React frameworks that use different attribute names.
示例:
🌐 Example:
{
"settings": {
"jsx-a11y": {
"attributes": {
"for": ["htmlFor", "for"]
}
}
}
}settings.jsx-a11y.components
类型:Record<string, string>
🌐 type: Record<string, string>
默认:{}
🌐 default: {}
要让你的自定义组件被检查为 DOM 元素,你可以提供一个将组件名称映射到 DOM 元素名称的映射表。
🌐 To have your custom components be checked as DOM elements, you can provide a mapping of your component names to the DOM element name.
示例:
🌐 Example:
{
"settings": {
"jsx-a11y": {
"components": {
"Link": "a",
"IconButton": "button"
}
}
}
}settings.jsx-a11y.polymorphicPropName
类型:string
🌐 type: string
一个可选设置,用于定义你的代码用来创建多态组件的属性。该设置将用于在需要语义上下文的规则中确定元素类型。
🌐 An optional setting that define the prop your code uses to create polymorphic components. This setting will be used to determine the element type in rules that require semantic context.
例如,如果你将 polymorphicPropName 设置为 as,那么这个元素:
🌐 For example, if you set the polymorphicPropName to as, then this element:
<Box as="h3">Hello</Box>将被视为 h3。如果未设置,该组件将被视为 Box。
🌐 Will be treated as an h3. If not set, this component will be treated as a Box.
settings.next
类型:object
🌐 type: object
配置Next.js插件规则。
🌐 Configure Next.js plugin rules.
settings.next.rootDir
类型:array | string
🌐 type: array | string
settings.next.rootDir[n]
类型:string
🌐 type: string
settings.react
类型:object
🌐 type: object
配置 React 插件规则。
🌐 Configure React plugin rules.
🌐 Derived from eslint-plugin-react
settings.react.formComponents
类型:array
🌐 type: array
默认:[]
🌐 default: []
用于替代表单中 <form> 的组件,例如 <Formik>。
🌐 Components used as alternatives to <form> for forms, such as <Formik>.
示例:
🌐 Example:
{
"settings": {
"react": {
"formComponents": [
"CustomForm",
// OtherForm is considered a form component and has an endpoint attribute
{ "name": "OtherForm", "formAttribute": "endpoint" },
// allows specifying multiple properties if necessary
{ "name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"] },
],
},
},
}settings.react.formComponents[n]
类型:object | string
🌐 type: object | string
settings.react.formComponents[n].attribute
类型:string
🌐 type: string
settings.react.formComponents[n].name
类型:string
🌐 type: string
settings.react.linkComponents
类型:array
🌐 type: array
默认:[]
🌐 default: []
用于替代 <a> 进行连接的组件,例如 <Link>。
🌐 Components used as alternatives to <a> for linking, such as <Link>.
示例:
🌐 Example:
{
"settings": {
"react": {
"linkComponents": [
"HyperLink",
// Use `linkAttribute` for components that use a different prop name
// than `href`.
{ "name": "MyLink", "linkAttribute": "to" },
// allows specifying multiple properties if necessary
{ "name": "Link", "linkAttribute": ["to", "href"] },
],
},
},
}settings.react.linkComponents[n]
类型:object | string
🌐 type: object | string
settings.react.linkComponents[n].attribute
类型:string
🌐 type: string
settings.react.linkComponents[n].name
类型:string
🌐 type: string
settings.react.version
类型:string
🌐 type: string
默认:null
🌐 default: null
用于针对特定版本规则的 React 版本。
🌐 React version to use for version-specific rules.
接受语义化版本(例如,“18.2.0”、“17.0”)。
🌐 Accepts semver versions (e.g., "18.2.0", "17.0").
示例:
🌐 Example:
{
"settings": {
"react": {
"version": "18.2.0",
},
},
}settings.vitest
类型:object
🌐 type: object
配置 Vitest 插件规则。
🌐 Configure Vitest plugin rules.
有关完整参考,请参见 eslint-plugin-vitest 的配置。
🌐 See eslint-plugin-vitest's configuration for a full reference.
settings.vitest.typecheck
类型:boolean
🌐 type: boolean
默认:false
🌐 default: false
是否启用 Vitest 规则的类型检查模式。启用后,某些规则将在 describe 块中跳过某些检查,以适应 TypeScript 类型检查的场景。
🌐 Whether to enable typecheck mode for Vitest rules. When enabled, some rules will skip certain checks for describe blocks to accommodate TypeScript type checking scenarios.
