跳转到内容

配置

允许传递一个JSON模式文件的路径。

我们为 biome.json 发布了一个JSON模式文件。

如果 @biomejs/biome 安装在 node_modules 文件夹中,你可以指定一个相对路径到 @biomejs/biome npm包的模式:

biome.json
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json"
}

如果你在解析物理文件时遇到问题,你可以使用在这个网站发布的文件:

biome.json
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json"
}

一个指向其他JSON文件的路径列表,这些文件将扩展当前的配置文件。

biome.json
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"extends": ["./formatter.json", "./linter.json"]
}
formatter.json
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"formatter": {
"indentSize": 2
},
"javascript": {
"formatter": {
"semicolons": "asNeeded"
}
}
}
linter.json
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"linter": {
"rules": {
"complexity": {
"noUselessConstructor": "off"
}
}
}
}

这个数组中定义的文件:

  • 必须存在于文件系统中;
  • 从定义 biome.json 文件的路径解析;
  • 必须是相对路径。不解析库路径;
  • 必须能被Biome访问,例如,Biome可能无法解析符号链接;
  • 将按顺序处理:从第一个到最后一个;
  • 可以覆盖相同的属性,但最终只有最后一个会被Biome使用;

源代码文件的最大允许大小(字节)。超过此限制的文件将出于性能原因被忽略。

默认值:1024*1024 (1MB)

一组Unix shell样式的模式。Biome会忽略匹配这些模式的文件和文件夹。

biome.json
{
"files": {
"ignore": ["scripts/*.js"]
}
}

一组Unix shell样式的模式。Biome只处理匹配这些模式的文件和文件夹。

biome.json
{
"files": {
"include": ["scripts/*.js"]
}
}

给出以下例子:

biome.json
{
"files": {
"include": ["scripts/**/*.js", "src/**/*.js"],
"ignore": ["scripts/**/*.js"]
}
}

只有匹配 src/**/*.js 模式的文件将被处理,而匹配 scripts/**/*.js 模式的文件将被忽略。

如果Biome遇到无法处理的文件,它将不会发出诊断。

biome.json
{
"files": {
"ignoreUnknown": true
}
}

默认值:false

一组用于将Biome与VCS软件集成的属性。

是否应让Biome与VCS客户端集成

默认值:false

客户端种类。

值:

  • "git"

Biome是否应使用VCS忽略文件。当 true 时,Biome将忽略ignore文件中指定的文件。

Biome应检查VCS文件的文件夹。默认情况下,Biome将使用找到 biome.json 的同一文件夹。

如果Biome找不到配置,它将尝试使用当前工作目录。如果找不到当前工作目录,Biome将不使用VCS集成,并将发出诊断。

启用Biome的linter

默认值:true

一组Unix shell样式的模式。

biome.json
{
"linter": {
"ignore": ["scripts/*.js"]
}
}

一组Unix shell样式的模式。Biome只处理匹配这些模式的文件和文件夹。

biome.json
{
"linter": {
"include": ["scripts/*.js"]
}
}

给出以下例子:

biome.json
{
"linter": {
"include": ["scripts/**/*.js", "src/**/*.js"],
"ignore": ["scripts/**/*.js"]
}
}

只有匹配 src/**/*.js 模式的文件将被lint,而匹配 scripts/**/*.js 模式的文件将被忽略。

启用所有组的推荐规则

默认值:true

启用或禁用所有组的所有规则

如果 recommendedall 都为 true,Biome将发出诊断信息并回退到默认设置。

biome.json
{
"linter": {
"enabled": true,
"rules": {
"all": true
}
}
}

也可以组合此标志以启用/禁用不同的规则组:

biome.json
{
"linter": {
"enabled": true,
"rules": {
"all": true,
"style": {
"all": false
},
"complexity": {
"all": false
}
}
}
}

在上面的例子中,Biome将启用所有规则,除了属于 stylecomplexity 组的规则。

影响单个组规则的选项。Biome支持以下组:

  • accessibility: Rules focused on preventing accessibility problems.
  • complexity: Rules that focus on inspecting complex code that could be simplified.
  • correctness: Rules that detect code that is guaranteed to be incorrect or useless.
  • performance: Rules catching ways your code could be written to run faster, or generally be more efficient.
  • security: Rules that detect potential security flaws.
  • style: Rules enforcing a consistent and idiomatic way of writing your code.
  • suspicious: Rules that detect code that is likely to be incorrect or useless.
  • nursery: New rules that are still under development. Nursery rules require explicit opt-in via configuration on stable versions because they may still have bugs or performance problems. They are enabled by default on nightly builds, but as they are unstable their diagnostic severity may be set to either error or warning, depending on whether we intend for the rule to be recommended or not when it eventually gets stabilized. Nursery rules get promoted to other groups once they become stable or may be removed. Rules that belong to this group are not subject to semantic version.
  • linter.rules.[group].recommended

    Section titled linter.rules.[group].recommended

    启用单个组的推荐规则。

    例子:

    biome.json
    {
    "linter": {
    "enabled": true,
    "rules": {
    "nursery": {
    "recommended": true
    }
    }
    }
    }

    启用单个组的所有规则。

    例子:

    biome.json
    {
    "linter": {
    "enabled": true,
    "rules": {
    "nursery": {
    "all": true
    }
    }
    }
    }

    这些选项适用于所有语言。 以下还有一些特定于语言的格式化选项。

    启用 Biome 的格式化器

    默认值:true

    一组Unix shell样式的模式。

    biome.json
    {
    "formatter": {
    "ignore": ["scripts/*.js"]
    }
    }

    一组Unix shell样式的模式。Biome只处理匹配这些模式的文件和文件夹。

    biome.json
    {
    "formatter": {
    "include": ["scripts/*.js"]
    }
    }

    给出以下例子:

    biome.json
    {
    "formatter": {
    "include": ["scripts/**/*.js", "src/**/*.js"],
    "ignore": ["scripts/**/*.js"]
    }
    }

    只有匹配 src/**/*.js 模式的文件将被格式化,而匹配 scripts/**/*.js 模式的文件将被忽略。

    允许格式化包含语法错误的文档。

    biome.json
    {
    "formatter": {
    "formatWithErrors": true
    }
    }

    默认值:false

    缩进的样式。可以是"tab""space"

    默认值:tab

    缩进应该是多大。

    默认值:2

    缩进应该是多大。

    默认值:2

    行结束的类型。

    • lf,仅换行符(\n),在Linux和macOS以及git仓库内部常见
    • crlf 回车 + 换行字符(\r\n),在Windows上常见
    • cr 仅回车字符(\r),非常罕见

    默认值:lf

    一行可以写多少个字符。

    默认值:80

    启用Biome的排序导入。

    默认值:true

    一组Unix shell样式的模式。Biome会忽略匹配这些模式的文件和文件夹。

    biome.json
    {
    "organizeImports": {
    "ignore": ["scripts/*.js"]
    }
    }

    一组Unix shell样式的模式。Biome只处理匹配这些模式的文件和文件夹。

    biome.json
    {
    "organizeImports": {
    "include": ["scripts/*.js"]
    }
    }

    给出以下例子:

    biome.json
    {
    "organizeImports": {
    "include": ["scripts/**/*.js", "src/**/*.js"],
    "ignore": ["scripts/**/*.js"]
    }
    }

    只有匹配 src/**/*.js 模式的文件会排序其导入,而匹配 scripts/**/*.js 模式的文件将被忽略。

    这些选项仅适用于JavaScript (和TypeScript) 文件。

    javascript.parser.unsafeParameterDecoratorsEnabled

    Section titled javascript.parser.unsafeParameterDecoratorsEnabled

    允许支持不安全/实验性参数装饰器。

    biome.json
    {
    "javascript": {
    "parser": {
    "unsafeParameterDecoratorsEnabled": true
    }
    }
    }

    默认值:false

    javascript.formatter.quoteStyle

    Section titled javascript.formatter.quoteStyle

    表示字符串字面值时使用的引号类型。可以是 singledouble

    默认值:double

    javascript.formatter.jsxQuoteStyle

    Section titled javascript.formatter.jsxQuoteStyle

    表示jsx字符串字面值时使用的引号类型。可以是 singledouble

    默认值:double

    javascript.formatter.quoteProperties

    Section titled javascript.formatter.quoteProperties

    对象内属性何时应该被引号包围。可以是 asNeededpreserve

    默认值:asNeeded

    javascript.formatter.trailingComma

    Section titled javascript.formatter.trailingComma

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

    • all,尾随逗号总是被添加
    • es5,尾随逗号只在旧版本的JavaScript支持的地方被添加
    • none,尾随逗号从不被添加

    默认值:all

    javascript.formatter.semicolons

    Section titled javascript.formatter.semicolons

    配置格式化器在哪里打印分号:

    • always,在每个语句的末尾总是添加分号;
    • asNeeded,只在需要的地方添加分号,以防止ASI

    默认值:always

    例子:

    biome.json
    {
    "javascript": {
    "formatter": {
    "semicolons": "asNeeded"
    }
    }
    }

    javascript.formatter.arrowParentheses

    Section titled javascript.formatter.arrowParentheses

    是否在箭头函数中添加非必须的括号:

    • always,总是添加括号;
    • asNeeded,只在需要时添加括号;

    默认值:always

    启用Biome的格式化器用于JavaScript (和其超级语言) 文件。

    默认值:true

    javascript.formatter.indentStyle

    Section titled javascript.formatter.indentStyle

    JavaScript (和其超级语言) 文件的缩进样式。可以是"tab""space"

    默认值:tab

    javascript.formatter.indentSize

    Section titled javascript.formatter.indentSize

    JavaScript (和其超级语言) 文件的缩进应该是多大。

    默认值:2

    javascript.formatter.lineEnding

    Section titled javascript.formatter.lineEnding

    JavaScript (和其超级语言) 文件的行结束类型。

    • lf,仅换行符(\n),在Linux和macOS以及git仓库内部常见
    • crlf 回车 + 换行字符(\r\n),在Windows上常见
    • cr 仅回车字符(\r),非常罕见

    默认值:lf

    javascript.formatter.lineWidth

    Section titled javascript.formatter.lineWidth

    在JavaScript (和其超级语言) 文件中一行可以写多少个字符。

    默认值:80

    Biome应忽略的全局名称列表(分析器,linter等)

    biome.json
    {
    "javascript": {
    "globals": ["$", "_", "externalVariable"]
    }
    }

    应用于JSON文件的选项。

    在JSON文件中启用注释的解析。

    biome.json
    {
    "json": {
    "parser": {
    "allowComments": true
    }
    }
    }

    json.parser.allowTrailingCommas

    Section titled json.parser.allowTrailingCommas

    在JSON文件中启用尾随逗号的解析。

    biome.json
    {
    "json": {
    "parser": {
    "allowTrailingCommas": true
    }
    }
    }

    启用Biome的格式化器用于JSON (和其超级语言) 文件。

    默认值:true

    JSON (和其超级语言) 文件的缩进样式。可以是"tab""space"

    默认值:tab

    JSON (和其超级语言) 文件的缩进应该是多大。

    默认值:2

    JSON (和其超级语言) 文件的行结束类型。

    • lf,仅换行符(\n),在Linux和macOS以及git仓库内部常见
    • crlf 回车 + 换行字符(\r\n),在Windows上常见
    • cr 仅回车字符(\r),非常罕见

    默认值:lf

    在JSON (和其超级语言) 文件中一行可以写多少个字符。

    默认值:80

    模式列表。

    使用此配置更改某些文件的工具行为。

    当文件与覆盖模式匹配时,该模式中指定的配置将覆盖顶级配置。

    模式的顺序很重要。如果一个文件可以匹配三个模式,只使用第一个。

    一组Unix shell样式的模式。Biome将不对匹配该模式的文件应用覆盖。

    biome.json
    {
    "overrides": [
    {
    "ignore": ["scripts/*.js"]
    }
    ]
    }

    一组Unix shell样式的模式。Biome将只对匹配这些模式的文件应用覆盖。

    biome.json
    {
    "overrides": [
    {
    "include": ["scripts/*.js"]
    }
    ]
    }

    它将包括 顶级格式化器 配置的选项,减去 ignoreinclude

    例如,可以修改在 glob 路径 generated/** 包含的某些文件的格式化器 lineWidthindentStyle

    biome.json
    {
    "formatter": {
    "lineWidth": 100
    },
    "overrides": [
    {
    "include": ["generated/**"],
    "formatter": {
    "lineWidth": 160,
    "indentStyle": "space"
    }
    }
    ]
    }

    它将包括 顶级 linter 配置的选项,减去 ignoreinclude

    可以为某些 glob 路径禁用某些规则,并为其他 glob 路径禁用 linter:

    biome.json
    {
    "linter": {
    "enabled": true,
    "rules": {
    "recommended": true
    }
    },
    "overrides": [
    {
    "include": ["lib/**"],
    "linter": {
    "rules": {
    "suspicious": {
    "noDebugger": "off"
    }
    }
    }
    },
    {
    "include": ["shims/**"],
    "linter": {
    "enabled": false
    }
    }
    ]
    }

    它将包括 顶级组织导入 的选项,减去 ignoreinclude

    它将包括 顶级 javascript 配置的选项。

    可以更改某些文件夹中的JavaScript文件的格式化行为:

    biome.json
    {
    "formatter": {
    "lineWidth": 120
    },
    "javascript": {
    "formatter": {
    "quoteStyle": "single"
    }
    },
    "overrides": [
    {
    "include": ["lib/**"],
    "javascript": {
    "formatter": {
    "quoteStyle": "double"
    }
    }
    }
    ]
    }

    它将包括 顶级 json 配置的选项。

    可以为某些JSON文件启用解析特性:

    biome.json
    {
    "linter": {
    "enabled": true,
    "rules": {
    "recommended": true
    }
    },
    "overrides": [
    {
    "include": [".vscode/**"],
    "json": {
    "parser": {
    "allowComments": true,
    "allowTrailingCommas": true
    }
    }
    }
    ]
    }