Skip to content

Oxfmt 配置选项

大多数选项与 Prettier 的选项相同,但并非全部。此外,部分选项是我们的自定义扩展。

arrowParens

type: "always" | "avoid"

在单个箭头函数参数周围包含括号。

  • 默认值: "always"

bracketSameLine

type: boolean

将多行 HTML(HTML、JSX、Vue、Angular)元素的 > 放在最后一行末尾, 而不是单独位于下一行(不适用于自闭合元素)。

  • 默认值: false

bracketSpacing

type: boolean

在对象字面量中打印括号之间的空格。

  • 默认值: true

embeddedLanguageFormatting

type: "auto" | "off"

控制是否格式化文件中的嵌入部分(例如,CSS-in-JS,或 JS-in-Vue 等)。

注意:XXX-in-JS 支持尚不完整。

  • 默认值: "auto"

endOfLine

type: "lf" | "crlf" | "cr"

指定应用的行尾字符。

注意:"auto" 不被支持。

  • 默认值: "lf"
  • 覆盖 .editorconfig.end_of_line

htmlWhitespaceSensitivity

type: "css" | "strict" | "ignore"

为 HTML、Vue、Angular 以及 Handlebars 指定全局空白敏感度。

  • 默认值: "css"

ignorePatterns

type: string[]

忽略匹配这些 glob 模式的文件。 模式基于 Oxfmt 配置文件的位置。

  • 默认值: []

insertFinalNewline

type: boolean

是否在文件末尾插入一个结尾换行符。

  • 默认值: true
  • 覆盖 .editorconfig.insert_final_newline

jsxSingleQuote

type: boolean

在 JSX 中使用单引号而非双引号。

  • 默认值: false

objectWrap

type: "preserve" | "collapse"

当对象字面量可以容纳在一行或跨越多行时,如何进行换行。

默认情况下,如果第一个属性前有换行符,则格式化为多行。 作者可利用此启发式规则来上下文提升可读性,尽管它也有一些缺点。

  • 默认值: "preserve"

overrides

type: array

文件特定的覆盖项。 当一个文件匹配多个覆盖项时,后面的覆盖项优先(数组顺序重要)。

  • 默认值: []

overrides[n]

type: object

overrides[n].excludeFiles

type: string[]

用于排除此覆盖项的 glob 模式。

overrides[n].files

type: string[]

用于匹配此覆盖项文件的 glob 模式。 所有模式相对于 Oxfmt 配置文件路径。

overrides[n].options

type: object

overrides[n].options.arrowParens

type: "always" | "avoid"

在单个箭头函数参数周围包含括号。

  • 默认值: "always"
overrides[n].options.bracketSameLine

type: boolean

将多行 HTML(HTML、JSX、Vue、Angular)元素的 > 放在最后一行末尾, 而不是单独位于下一行(不适用于自闭合元素)。

  • 默认值: false
overrides[n].options.bracketSpacing

type: boolean

在对象字面量中打印括号之间的空格。

  • 默认值: true
overrides[n].options.embeddedLanguageFormatting

type: "auto" | "off"

控制是否格式化文件中的嵌入部分(例如,CSS-in-JS,或 JS-in-Vue 等)。

注意:XXX-in-JS 支持尚不完整。

  • 默认值: "auto"
overrides[n].options.endOfLine

type: "lf" | "crlf" | "cr"

指定应用的行尾字符。

注意:"auto" 不被支持。

  • 默认值: "lf"
  • 覆盖 .editorconfig.end_of_line
overrides[n].options.htmlWhitespaceSensitivity

type: "css" | "strict" | "ignore"

为 HTML、Vue、Angular 以及 Handlebars 指定全局空白敏感度。

  • 默认值: "css"
overrides[n].options.insertFinalNewline

type: boolean

是否在文件末尾插入一个结尾换行符。

  • 默认值: true
  • 覆盖 .editorconfig.insert_final_newline
overrides[n].options.jsxSingleQuote

type: boolean

在 JSX 中使用单引号而非双引号。

  • 默认值: false
overrides[n].options.objectWrap

type: "preserve" | "collapse"

当对象字面量可以容纳在一行或跨越多行时,如何进行换行。

默认情况下,如果第一个属性前有换行符,则格式化为多行。 作者可利用此启发式规则来上下文提升可读性,尽管它也有一些缺点。

  • 默认值: "preserve"
overrides[n].options.printWidth

type: integer

指定打印机将在何处换行的行长度。

如果您不希望在格式化 Markdown 时进行换行,可以将 proseWrap 选项设置为禁用它。

  • 默认值: 100
  • 覆盖 .editorconfig.max_line_length
overrides[n].options.proseWrap

type: "always" | "never" | "preserve"

如何换行段落文本。

默认情况下,格式化器不会更改 Markdown 文本中的换行,因为某些服务使用对换行敏感的渲染器,例如 GitHub 评论和 BitBucket。 要将段落内容换行到打印宽度,请将此选项改为 "always"。 如果您希望强制所有段落块都放在单行上,并依赖编辑器/查看器的软换行,请使用 "never"

  • 默认值: "preserve"
overrides[n].options.quoteProps

type: "as-needed" | "consistent" | "preserve"

更改对象中属性被引号包围的时机。

  • 默认值: "as-needed"
overrides[n].options.semi

type: boolean

在语句末尾打印分号。

  • 默认值: true
overrides[n].options.singleAttributePerLine

type: boolean

在 HTML、Vue 和 JSX 中强制每行仅一个属性。

  • 默认值: false
overrides[n].options.singleQuote

type: boolean

使用单引号而非双引号。

对于 JSX,您可以设置 jsxSingleQuote 选项。

  • 默认值: false
overrides[n].options.sortImports

type: object

排序导入语句。

使用与 eslint-plugin-perfectionist/sort-imports 类似的算法。 详细信息请参阅每个字段的文档。

  • 默认值: 已禁用
overrides[n].options.sortImports.customGroups

type: array

定义您自己的分组以匹配非常具体的导入。

customGroups 列表是有序的:第一个匹配元素的定义将被使用。 自定义分组具有比任何预定义分组更高的优先级。

如果您希望预定义分组优先于自定义分组, 您必须编写一个与预定义分组相同作用的自定义分组定义,并将其置于列表开头。

如果您指定多个条件,如 elementNamePatternselectormodifiers, 则导入必须同时满足所有条件才能匹配该自定义分组(使用逻辑与)。

  • 默认值: []

####### overrides[n].options.sortImports.customGroups[n]

type: object

######## overrides[n].options.sortImports.customGroups[n].elementNamePattern

type: string[]

默认值: []

用于匹配此分组导入源的 glob 模式列表。

######## overrides[n].options.sortImports.customGroups[n].groupName

type: string

默认值: ""

自定义分组名称,用于 groups 选项中。

######## overrides[n].options.sortImports.customGroups[n].modifiers

type: string[]

用于匹配导入特征的修饰符。 所有指定的修饰符都必须存在(逻辑与)。

可能的值: "side_effect", "type", "value", "default", "wildcard", "named"

######## overrides[n].options.sortImports.customGroups[n].selector

type: string

用于匹配导入类型的选择器。

可能的值: "type", "side_effect_style", "side_effect", "style", "index", "sibling", "parent", "subpath", "internal", "builtin", "external", "import"

overrides[n].options.sortImports.groups

type: array

指定用于排序的预定义导入分组列表。

每个导入将被分配一个在 groups 选项中指定的单一分组(如果没有匹配,则为 unknown 分组)。 groups 选项中项目的顺序决定了分组的排列方式。

在给定分组内,成员将根据 typeorderignoreCase 等选项进行排序。

通过将分组放入数组中,可以组合多个分组。 数组中分组的顺序无关紧要。 数组中所有分组的成员将一起排序,仿佛它们属于同一个分组。

预定义分组由单个选择器和潜在的多个修饰符定义。 您可以按任意顺序输入修饰符,但选择器必须始终放在最后。

选择器列表按从最重要到最不重要的顺序排序:

  • type — TypeScript 类型导入。
  • side_effect_style — 带副作用风格的导入。
  • side_effect — 带副作用的导入。
  • style — 样式导入。
  • index — 当前目录的主文件。
  • sibling — 同一目录中的模块。
  • parent — 父目录中的模块。
  • subpath — Node.js 子路径导入。
  • internal — 您的内部模块。
  • builtin — Node.js 内建模块。
  • external — 项目中安装的外部模块。
  • import — 任何导入。

修饰符列表按从最重要到最不重要的顺序排序:

  • side_effect — 带副作用的导入。

  • type — TypeScript 类型导入。

  • value — 值导入。

  • default — 包含默认导出的导入。

  • wildcard — 包含通配符(* as)导出的导入。

  • named — 至少包含一个命名导出的导入。

  • 默认值: 见下文

json
["builtin", "external", ["internal", "subpath"], ["parent", "sibling", "index"], "style", "unknown"]

此外,您可以通过在 groups 列表中特定位置包含一个 { "newlinesBetween": boolean } 标记对象,来覆盖全局的 newlinesBetween 设置。

####### overrides[n].options.sortImports.groups[n]

type: array | string

overrides[n].options.sortImports.ignoreCase

type: boolean

指定排序是否区分大小写。

  • 默认值: true
overrides[n].options.sortImports.internalPattern

type: string[]

指定用于识别内部导入的前缀。

这有助于将您的模块与外部依赖项区分开。

  • 默认值: ["~/", "@/"]
overrides[n].options.sortImports.newlinesBetween

type: boolean

指定是否在分组之间添加换行符。

当为 false 时,分组之间不添加换行符。

  • 默认值: true
overrides[n].options.sortImports.order

type: "asc" | "desc"

指定应按升序还是降序排序。

  • 默认值: "asc"
overrides[n].options.sortImports.partitionByComment

type: boolean

启用使用注释将导入分隔为逻辑组。

当为 true 时,所有注释都将被视为分隔符,创建分区。

js
import { b1, b2 } from "b";
// PARTITION
import { a } from "a";
import { c } from "c";
  • 默认值: false
overrides[n].options.sortImports.partitionByNewline

type: boolean

启用空行将导入分隔为逻辑组。

当为 true 时,如果导入之间存在空行,格式化器将不会对其进行排序。 这有助于保持逻辑分组成员的既定顺序。

js
import { b1, b2 } from "b";

import { a } from "a";
import { c } from "c";
  • 默认值: false
overrides[n].options.sortImports.sortSideEffects

type: boolean

指定是否应对带副作用的导入进行排序。

出于安全原因,默认情况下禁用对带副作用导入的排序。

  • 默认值: false
overrides[n].options.sortPackageJson

type: object | boolean

package.json 键进行排序。

该算法与 prettier-plugin-sort-packagejson 不兼容。 但我们认为它更清晰且更易于导航。 详细信息请参见每个字段的文档。

  • 默认值: true
overrides[n].options.sortPackageJson.sortScripts

type: boolean

按字母顺序对 scripts 字段进行排序。

  • 默认值: false
overrides[n].options.sortTailwindcss

type: object

对 Tailwind CSS 类名进行排序。

使用与 prettier-plugin-tailwindcss 相同的算法。 选项名称省略了原始插件中使用的 tailwind 前缀(例如,config 而非 tailwindConfig)。 详细信息请参见每个字段的文档。

  • 默认值: 已禁用
overrides[n].options.sortTailwindcss.attributes

type: string[]

除了 classclassName 外需要排序的附加属性列表(精确匹配)。

注意:正则表达式模式尚未支持。

  • 默认值: []
  • 示例: ["myClassProp", ":class"]
overrides[n].options.sortTailwindcss.config

type: string

您的 Tailwind CSS 配置文件路径(v3)。

注意:路径相对于 Oxfmt 配置文件进行解析。

  • 默认值: 自动查找 "tailwind.config.js"
overrides[n].options.sortTailwindcss.functions

type: string[]

需要对其参数进行排序的自定义函数名称列表(精确匹配)。

注意:正则表达式模式尚未支持。

  • 默认值: []
  • 示例: ["clsx", "cn", "cva", "tw"]
overrides[n].options.sortTailwindcss.preserveDuplicates

type: boolean

保留重复的类名。

  • 默认值: false
overrides[n].options.sortTailwindcss.preserveWhitespace

type: boolean

保留类名周围的空格。

  • 默认值: false
overrides[n].options.sortTailwindcss.stylesheet

type: string

您的 Tailwind CSS 样式表路径(v4)。

注意:路径相对于 Oxfmt 配置文件进行解析。

  • 默认值: 安装的 Tailwind CSS 的 theme.css
overrides[n].options.tabWidth

type: integer

指定每级缩进的空格数。

  • 默认值: 2
  • 覆盖 .editorconfig.indent_size
overrides[n].options.trailingComma

type: "all" | "es5" | "none"

在多行逗号分隔的语法结构中尽可能地打印尾随逗号。

例如,单行数组永远不会获得尾随逗号。

  • 默认值: "all"
overrides[n].options.useTabs

type: boolean

使用制表符而非空格进行缩进。

  • 默认值: false
  • 覆盖 .editorconfig.indent_style
overrides[n].options.vueIndentScriptAndStyle

type: boolean

在 Vue 文件中是否对 <script><style> 标签内的代码进行缩进。

  • 默认值: false

printWidth

type: integer

指定打印机将在何处换行的行长度。

如果您不希望在格式化 Markdown 时进行换行,可以将 proseWrap 选项设置为禁用它。

  • 默认值: 100
  • 覆盖 .editorconfig.max_line_length

proseWrap

type: "always" | "never" | "preserve"

如何换行段落文本。

默认情况下,格式化器不会更改 Markdown 文本中的换行,因为某些服务使用对换行敏感的渲染器,例如 GitHub 评论和 BitBucket。 要将段落内容换行到打印宽度,请将此选项改为 "always"。 如果您希望强制所有段落块都放在单行上,并依赖编辑器/查看器的软换行,请使用 "never"

  • 默认值: "preserve"

quoteProps

type: "as-needed" | "consistent" | "preserve"

更改对象中属性被引号包围的时机。

  • 默认值: "as-needed"

semi

type: boolean

在语句末尾打印分号。

  • 默认值: true

singleAttributePerLine

type: boolean

在 HTML、Vue 和 JSX 中强制每行仅一个属性。

  • 默认值: false

singleQuote

type: boolean

使用单引号而非双引号。

对于 JSX,您可以设置 jsxSingleQuote 选项。

  • 默认值: false

sortImports

type: object

排序导入语句。

使用与 eslint-plugin-perfectionist/sort-imports 类似的算法。 详细信息请参阅每个字段的文档。

  • 默认值: 已禁用

sortImports.customGroups

type: array

定义您自己的分组以匹配非常具体的导入。

customGroups 列表是有序的:第一个匹配元素的定义将被使用。 自定义分组具有比任何预定义分组更高的优先级。

如果您希望预定义分组优先于自定义分组, 您必须编写一个与预定义分组相同作用的自定义分组定义,并将其置于列表开头。

如果您指定多个条件,如 elementNamePatternselectormodifiers, 则导入必须同时满足所有条件才能匹配该自定义分组(使用逻辑与)。

  • 默认值: []

sortImports.customGroups[n]

type: object

sortImports.customGroups[n].elementNamePattern

type: string[]

默认值: []

用于匹配此分组导入源的 glob 模式列表。

sortImports.customGroups[n].groupName

type: string

默认值: ""

自定义分组名称,用于 groups 选项中。

sortImports.customGroups[n].modifiers

type: string[]

用于匹配导入特征的修饰符。 所有指定的修饰符都必须存在(逻辑与)。

可能的值: "side_effect", "type", "value", "default", "wildcard", "named"

sortImports.customGroups[n].selector

type: string

用于匹配导入类型的选择器。

可能的值: "type", "side_effect_style", "side_effect", "style", "index", "sibling", "parent", "subpath", "internal", "builtin", "external", "import"

sortImports.groups

type: array

指定用于排序的预定义导入分组列表。

每个导入将被分配一个在 groups 选项中指定的单一分组(如果没有匹配,则为 unknown 分组)。 groups 选项中项目的顺序决定了分组的排列方式。

在给定分组内,成员将根据 typeorderignoreCase 等选项进行排序。

通过将分组放入数组中,可以组合多个分组。 数组中分组的顺序无关紧要。 数组中所有分组的成员将一起排序,仿佛它们属于同一个分组。

预定义分组由单个选择器和潜在的多个修饰符定义。 您可以按任意顺序输入修饰符,但选择器必须始终放在最后。

选择器列表按从最重要到最不重要的顺序排序:

  • type — TypeScript 类型导入。
  • side_effect_style — 带副作用风格的导入。
  • side_effect — 带副作用的导入。
  • style — 样式导入。
  • index — 当前目录的主文件。
  • sibling — 同一目录中的模块。
  • parent — 父目录中的模块。
  • subpath — Node.js 子路径导入。
  • internal — 您的内部模块。
  • builtin — Node.js 内建模块。
  • external — 项目中安装的外部模块。
  • import — 任何导入。

修饰符列表按从最重要到最不重要的顺序排序:

  • side_effect — 带副作用的导入。

  • type — TypeScript 类型导入。

  • value — 值导入。

  • default — 包含默认导出的导入。

  • wildcard — 包含通配符(* as)导出的导入。

  • named — 至少包含一个命名导出的导入。

  • 默认值: 见下文

json
["builtin", "external", ["internal", "subpath"], ["parent", "sibling", "index"], "style", "unknown"]

此外,您可以通过在 groups 列表中特定位置包含一个 { "newlinesBetween": boolean } 标记对象,来覆盖全局的 newlinesBetween 设置。

sortImports.groups[n]

type: array | string

sortImports.ignoreCase

type: boolean

指定排序是否区分大小写。

  • 默认值: true

sortImports.internalPattern

type: string[]

指定用于识别内部导入的前缀。

这有助于将您的模块与外部依赖项区分开。

  • 默认值: ["~/", "@/"]

sortImports.newlinesBetween

type: boolean

指定是否在分组之间添加换行符。

当为 false 时,分组之间不添加换行符。

  • 默认值: true

sortImports.order

type: "asc" | "desc"

指定应按升序还是降序排序。

  • 默认值: "asc"

sortImports.partitionByComment

type: boolean

启用使用注释将导入分隔为逻辑组。

当为 true 时,所有注释都将被视为分隔符,创建分区。

js
import { b1, b2 } from "b";
// PARTITION
import { a } from "a";
import { c } from "c";
  • 默认值: false

sortImports.partitionByNewline

type: boolean

启用空行将导入分隔为逻辑组。

当为 true 时,如果导入之间存在空行,格式化器将不会对其进行排序。 这有助于保持逻辑分组成员的既定顺序。

js
import { b1, b2 } from "b";

import { a } from "a";
import { c } from "c";
  • 默认值: false

sortImports.sortSideEffects

type: boolean

指定是否应对带副作用的导入进行排序。

出于安全原因,默认情况下禁用对带副作用导入的排序。

  • 默认值: false

sortPackageJson

type: object | boolean

package.json 键进行排序。

该算法与 prettier-plugin-sort-packagejson 不兼容。 但我们认为它更清晰且更易于导航。 详细信息请参见每个字段的文档。

  • 默认值: true

sortPackageJson.sortScripts

type: boolean

按字母顺序对 scripts 字段进行排序。

  • 默认值: false

sortTailwindcss

type: object

对 Tailwind CSS 类名进行排序。

使用与 prettier-plugin-tailwindcss 相同的算法。 选项名称省略了原始插件中使用的 tailwind 前缀(例如,config 而非 tailwindConfig)。 详细信息请参见每个字段的文档。

  • 默认值: 已禁用

sortTailwindcss.attributes

type: string[]

除了 classclassName 外需要排序的附加属性列表(精确匹配)。

注意:正则表达式模式尚未支持。

  • 默认值: []
  • 示例: ["myClassProp", ":class"]

sortTailwindcss.config

type: string

您的 Tailwind CSS 配置文件路径(v3)。

注意:路径相对于 Oxfmt 配置文件进行解析。

  • 默认值: 自动查找 "tailwind.config.js"

sortTailwindcss.functions

type: string[]

需要对其参数进行排序的自定义函数名称列表(精确匹配)。

注意:正则表达式模式尚未支持。

  • 默认值: []
  • 示例: ["clsx", "cn", "cva", "tw"]

sortTailwindcss.preserveDuplicates

type: boolean

保留重复的类名。

  • 默认值: false

sortTailwindcss.preserveWhitespace

type: boolean

保留类名周围的空格。

  • 默认值: false

sortTailwindcss.stylesheet

type: string

您的 Tailwind CSS 样式表路径(v4)。

注意:路径相对于 Oxfmt 配置文件进行解析。

  • 默认值: 安装的 Tailwind CSS 的 theme.css

tabWidth

type: integer

指定每级缩进的空格数。

  • 默认值: 2
  • 覆盖 .editorconfig.indent_size

trailingComma

type: "all" | "es5" | "none"

在多行逗号分隔的语法结构中尽可能地打印尾随逗号。

例如,单行数组永远不会获得尾随逗号。

  • 默认值: "all"

useTabs

type: boolean

使用制表符而非空格进行缩进。

  • 默认值: false
  • 覆盖 .editorconfig.indent_style

vueIndentScriptAndStyle

type: boolean

在 Vue 文件中是否对 <script><style> 标签内的代码进行缩进。

  • 默认值: false