You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Biome仅允许tests文件夹使用any类型?

解决Biome分文件夹差异化代码检查的问题

你可以通过Biome配置文件中的overrides字段实现差异化规则配置,具体实现方式如下:

  1. 在全局配置中开启针对src文件夹的严格规则,将lint.suspicious.noExplicitAny设为error级别,确保src目录下的代码严格禁止any类型。
  2. 通过overrides数组匹配tests文件夹下的所有文件,单独关闭该规则,允许测试代码使用any。

完整的biome.json配置示例:

{
  "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
  "organizeImports": {
    "enabled": true
  },
  "linter": {
    "enabled": true,
    "rules": {
      "suspicious": {
        "noExplicitAny": "error"
      }
      // 可在此添加其他全局严格检查规则
    }
  },
  "overrides": [
    {
      "include": ["tests/**/*"],
      "linter": {
        "rules": {
          "suspicious": {
            "noExplicitAny": "off"
          }
        }
      }
    }
  ]
}

配置说明

  • 全局规则部分:noExplicitAny设为error,会对所有未被overrides覆盖的文件生效(即src文件夹),保证代码严格性。
  • overrides部分:include字段用通配符匹配tests下的所有文件,在该区块内单独将noExplicitAny设为off,允许测试代码使用any类型。
  • 若需对tests文件夹调整其他规则,直接在这个overrides块的rules中添加对应配置即可。

内容的提问来源于stack exchange,提问作者allevo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 04:19:51