编辑
2025-07-01
默认分类
00

目录

一个biome配置模板

一个biome配置模板

下面是一个biome配置模板,主要适配了 ts格式的规则

json
{ // ================================================================== // 基础配置 // ================================================================== "$schema": "https://biomejs.dev/schemas/2.0.6/schema.json", // "extends": null, // 可继承其他配置(如:"biome:recommended") // ================================================================== // 文件系统配置 // ================================================================== "files": { // 文件大小限制(字节) "maxSize": 1048576, // 默认 1MB // 包含/排除规则(示例): // "include": ["src/**/*.{js,ts}"], // 明确包含的文件模式 // "ignore": ["temp/**"], // 要忽略的文件模式 "ignoreUnknown": false // 是否忽略未知文件类型(默认false) }, // ================================================================== // 版本控制(VCS)配置 // ================================================================== "vcs": { "enabled": false, // 是否启用VCS集成(默认false) "clientKind": "git", // 版本控制系统类型(git/svn等,默认git) "useIgnoreFile": false, // 是否使用.gitignore等文件(默认false) "root": ".", // VCS根目录(默认当前目录) "defaultBranch": "main" // 默认分支名称(默认main) }, // ================================================================== // 代码检查器(Linter)配置 // ================================================================== "linter": { "enabled": true, // 是否启用代码检查(默认true) // 文件包含/排除规则 "includes": [ "**", // 默认检查所有文件 "!**/__fixtures__", // 排除测试夹具目录 "!**/__mocks__", // 排除模拟目录 "!**/dist", // 排除构建输出目录 "!**/node_modules", // 排除依赖目录 "!**/.yarn", //排除 Yarn 缓存目录 "!**/.history", // 排除历史记录文件 "!**/build", // 排除构建目录 "!**/coverage", // 排除测试覆盖率报告目录 "!**/jest.config.js", // 排除 Jest 配置文件 "!**/jest.transform.js", // 排除 Jest 转换文件 "!**/docusaurus.config.ts", // 排除 Docusaurus 配置文件 "!**/sidebars.js", // 排除侧边栏配置文件 "!**/*.md", // 排除 Markdown 文件 "!**/lib" // 排除 lib 目录 ], // ====================== // 规则集配置 // ====================== "rules": { "recommended": false, // 是否启用全部推荐规则(默认true) // 代码复杂度规则 "complexity": { "noBannedTypes": "error", // 禁止使用特定类型(如any) "noUselessTypeConstraint": "error", // 禁止无用的类型约束 "noForEach": "off" // 是否禁用forEach(默认off) }, // 代码正确性规则 "correctness": { "noPrecisionLoss": "error", // 禁止数字精度丢失 "noUnusedVariables": "off" // 未使用变量检查(默认off) }, // 实验性规则(可能变更) "nursery": { "useSortedClasses": "error" // 强制类成员排序 }, // 性能相关规则 "performance": { "recommended": true // 启用全部推荐性能规则(默认true) }, // 安全相关规则 "security": { "recommended": true // 启用全部推荐安全规则(默认true) }, // 代码风格规则 "style": { "noNamespace": "error", // 禁止namespace语法 "useAsConstAssertion": "error", // 强制as const断言 "noUselessElse": "error" // 禁止无用else语句 }, // 可疑代码模式检测 "suspicious": { "noExtraNonNullAssertion": "error", // 禁止多余的非空断言 "noMisleadingInstantiator": "error", // 检测误导性的实例化 "noUnsafeDeclarationMerging": "error", // 不安全的声明合并 "noExplicitAny": "off", // 禁止使用any类型(默认off,从one-biome补充) "noArrayIndexKey": "off" // 禁止数组索引作为key(默认off,从one-biome补充) } } }, // ================================================================== // 代码格式化(Formatter)配置 // ================================================================== "formatter": { "enabled": true, // 是否启用格式化(默认true) // 格式化范围控制 "includes": ["**", "!**/lib"], // 包含/排除文件 // "ignore": ["**/node_modules/**", "**/dist/**"], // 默认 [] // 核心格式化选项 "formatWithErrors": false, // 是否在格式化时显示错误(默认false) "indentStyle": "space", // 缩进风格(space/tab,默认tab) "indentWidth": 2, // 缩进空格数(默认2) "lineWidth": 120, // 行宽限制(默认80) "lineEnding": "lf", // 行尾符(lf/crlf,默认lf) "attributePosition": "auto" // HTML属性位置(auto/multiline等,默认auto) }, // ================================================================== // 辅助功能配置 // ================================================================== "assist": { "actions": { "source": { "organizeImports": "on" // 自动整理import语句(默认on) } } }, // ================================================================== // JavaScript 特定配置 // ================================================================== "javascript": { // 解析器选项 "parser": { "unsafeParameterDecoratorsEnabled": false // 禁用不安全的装饰器语法(默认false) }, // JS格式化风格 "formatter": { "quoteStyle": "single", // 字符串引号风格(默认double) "jsxQuoteStyle": "double", // JSX引号风格(默认double) "quoteProperties": "asNeeded", // 对象属性引号规则(asNeeded/preserve,默认asNeeded) "trailingCommas": "all", // 尾随逗号规则(all/es5/none,默认all) "semicolons": "asNeeded", // 分号使用规则(always/asNeeded,默认always) "arrowParentheses": "asNeeded", // 箭头函数括号规则(always/asNeeded,默认always) "enabled": true, // 是否启用JS格式化(默认true) "indentStyle": "space", // 缩进风格(space/tab,默认tab) "indentWidth": 2, // 缩进空格数(默认2) "lineEnding": "lf", // 行尾符(lf/crlf,默认lf) "lineWidth": 120, // 行宽限制(默认80) "bracketSameLine": false, // 括号是否同行(默认false) "bracketSpacing": true, // 括号空格(默认true) "attributePosition": "auto" // 属性位置(默认auto) }, // 全局变量白名单 "globals": ["$", "_", "externalVariable"], // 默认[] // JSX运行时配置 "jsxRuntime": "reactClassic", // JSX转换方式(transparent/reactClassic,默认transparent) "linter": { "enabled": true // 是否启用JS检查(默认true) } }, // ================================================================== // JSON 文件配置 // ================================================================== "json": { "parser": { "allowComments": true // 允许JSON中的注释(默认false) }, "formatter": { "enabled": true, // 是否启用JSON格式化(默认true) "indentStyle": "space", // 缩进风格(space/tab,默认tab) "indentWidth": 2, // 缩进空格数(默认2) "lineEnding": "lf", // 行尾符(lf/crlf,默认lf) "lineWidth": 120, // 行宽限制(默认80) "trailingCommas": "none" // 尾随逗号规则(none/all,默认none) }, "linter": { "enabled": true // 是否启用JSON检查(默认true) } }, // ================================================================== // CSS 文件配置 // ================================================================== "css": { "parser": { "cssModules": true // 启用CSS Modules语法(默认false) }, "formatter": { "enabled": false, // 是否启用CSS格式化(默认false) "indentStyle": "space", // 缩进风格(space/tab,默认tab) "indentWidth": 2, // 缩进空格数(默认2) "lineEnding": "lf", // 行尾符(lf/crlf,默认lf) "lineWidth": 80, // 行宽限制(默认80) "quoteStyle": "double" // CSS引号风格(double/single,默认double) }, "linter": { "enabled": false // 是否启用CSS检查(默认false) } }, // ================================================================== // 文件类型覆盖规则 // ================================================================== "overrides": [ { // TypeScript文件特殊规则 "includes": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"], "linter": { "rules": { "correctness": { "noConstAssign": "off", // 允许常量重新赋值 "noGlobalObjectCalls": "off", "noInvalidConstructorSuper": "off", "noSetterReturn": "off", "noUndeclaredVariables": "off", "noUnreachable": "off", "noUnreachableSuper": "off", "noInvalidBuiltinInstantiation": "off" }, // TypeScript风格规则 "style": { "useConst": "error" // 强制使用const }, // TypeScript特定规则 "suspicious": { "noDuplicateClassMembers": "off", "noDuplicateObjectKeys": "off", "noDuplicateParameters": "off", "noFunctionAssign": "off", "noImportAssign": "off", "noRedeclare": "off", "noUnsafeNegation": "off", "useGetterReturn": "off", "noVar": "error" // 禁止使用var }, "complexity": { "noArguments": "error" } } } } ] }

本文作者:任浪漫

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!