Skip to content
雲里
里雾

Biome v2 Expo 项目配置

biome 开发 更新于 2026/4/13

本页介绍 Biome v2 相对 v1 的配置 schema 破坏性变更,说明如何通过 overrides 解决 Expo Router 强制使用 export default 与 Biome noDefaultExport 规则的冲突,并给出推荐的完整配置和 VS Code 集成方案。

概述

这页主要解决两个实际问题:一是 Biome v2 相比 v1 的配置格式发生了破坏性变化,旧配置不能直接复用;二是 Expo Router 要求路由文件使用 export default,而很多团队又希望在其余代码中禁用默认导出。本文给出一套适合 Expo 项目的 Biome v2 配置模板和配套编辑器设置。

迁移差异

Biome 2.x 对配置 schema 做了清理,直接复用 v1 的 biome.json 会报错或静默失效:

v1 写法v2 写法说明
"organizeImports": { "enabled": true }移入 "assist"organizeImports 顶层 key 已移除
"files": { "ignore": [...] }"files": { "includes": [...] }ignore 改为 includes(语义也变了:用 ! 前缀排除)
"overrides": [{ "include": [...] }]"overrides": [{ "includes": [...] }]同上,includeincludes

Expo Router 的 default export 冲突

Expo Router 要求 app/ 目录下的所有路由文件使用 export default,这与 Biome 的 noDefaultExport 规则冲突。

项目约定是除路由文件外一律用具名导出,所以最佳方案是用 overridesapp/ 目录单独关闭这条规则:

{
  "overrides": [
    {
      "includes": ["app/**/*.tsx", "app/**/*.ts"],
      "linter": {
        "rules": {
          "style": {
            "noDefaultExport": "off"
          }
        }
      }
    }
  ]
}

推荐完整配置

{
  "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
  "files": {
    "includes": [
      "**/*.ts",
      "**/*.tsx",
      "**/*.js",
      "**/*.jsx",
      "!node_modules/**",
      "!.expo/**",
      "!dist/**"
    ]
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2,
    "lineWidth": 100
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "correctness": {
        "noUnusedVariables": "warn",
        "noUnusedImports": "warn"
      },
      "suspicious": {
        "noExplicitAny": "error"
      }
    }
  },
  "assist": {
    "actions": {
      "source": {
        "organizeImports": "on"
      }
    }
  },
  "overrides": [
    {
      "includes": ["app/**/*.tsx", "app/**/*.ts"],
      "linter": {
        "rules": {
          "style": {
            "noDefaultExport": "off"
          }
        }
      }
    }
  ]
}

VS Code 集成

安装 biomejs.biome 扩展后,在 .vscode/settings.json 中配置:

{
  "editor.defaultFormatter": "biomejs.biome",
  "editor.formatOnSave": true,
  "prettier.enable": false,
  "[typescript]": {
    "editor.defaultFormatter": "biomejs.biome"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "biomejs.biome"
  }
}

必须显式关闭 Prettier,否则两个格式化器会冲突——Prettier 扩展默认激活,会在 Biome 之后再格式化一次,导致保存时代码闪烁或被 Prettier 改回去。

package.json scripts

{
  "scripts": {
    "lint": "biome check .",
    "lint:fix": "biome check --write .",
    "format": "biome format --write ."
  }
}

biome check 同时运行 lint + format 检查(不写入)。--write 标志自动修复可修复的问题。日常开发 lint:fix 最常用,提交前 CI 跑 lint(只检查不修改,有问题就失败)。

参见

参考

版本说明