@moontern-labs / code-budget
具有无限工具和验证的显式实现loc上限。
npm install --save-dev @moontern-labs/[email protected]
npx code-budget # infer and explain when unconfigured
npx code-budget init --scope simple-tool
npx code-budget # enforce the committed configuration
对于补丁版本, npm run bump 增量 x.x.N 来 x.x.(N + 1) 和
更新lockfile和版本化的源代码/文档引用。使用
npm run bump -- --dry-run.
实现度量产品代码。工具测量开发、构建、 分别释放、线头和操作支持,没有上限。测试中, 仅测试的帮助程序和fixture也被测量,但不受限制。文档、锁文件、许可证和包元数据 单独报告。将源文件移动到不匹配的目录或重叠目录中 区域配置检查失败。
配置
import { defineConfig } from "@moontern-labs/code-budget";
export default defineConfig({
scope: "platform",
areas: [
{
name: "runtime",
kind: "implementation",
include: ["src/**", "bin/**"],
exclude: ["**/*.test.*", "**/__tests__/**"],
},
{
name: "tooling",
kind: "tooling",
include: ["scripts/**"],
exclude: ["scripts/test/**", "**/*.test.*"],
},
{
name: "tests",
kind: "verification",
include: ["test/**", "tests/**", "**/*.test.*", "**/__tests__/**"],
exclude: ["**/fixtures/**"],
},
{
name: "fixtures",
kind: "verification",
include: ["**/fixtures/**"],
},
{
name: "generated-engine",
kind: "excluded",
include: ["engine/generated/**"],
reason: "Reproduced from the checksum-pinned upstream source archive.",
},
],
});
工具违约
推理和 init 使用相同的分类:
| 路径 | 分类 |
|---|---|
一切都在 .github/**,包括测试和模板 | tooling |
根 scripts/**, tools/**, tooling/** | tooling,除了认可的测试和装置 |
根 .husky/** | tooling,除了认可的测试和装置 |
src/**, lib/**, app/**, packages/**, bin/** | implementation,但认可的工具、测试和夹具除外 |
目录命名 test, tests, spec, specs,或者 __tests__;文件匹配 *.test.* 或者 *.spec.* | verification外, .github/** |
目录命名 fixture, fixtures,或者 __fixtures__ | verification外, .github/** |
工具配置模式匹配任何深度。支持 NAME.config.EXT
文件使用这些名称: code-budget, vite, vitest, webpack, rollup,
esbuild, tsup, babel, eslint, prettier, jest, playwright, cypress,
next, nuxt, svelte, astro, postcss, tailwind. 支持扩展
是 js, cjs, mjs, ts, cts, mts, json.
其他工具模式包括 tsconfig*.json; .eslintrc, .prettierrc,
.babelrc,可伸缩或可伸缩 js, cjs, mjs, json, yaml,或者
yml; Makefile, GNUmakefile, Justfile, justfile, Rakefile, Dockerfile,
和 Dockerfile.*;的YAML文件 compose, compose.*,
docker-compose,或者 docker-compose.*. 认可的测试和装置
优先于外部的这些模式 .github/**.
这些默认值不能确定脚本的目的。添加明确的区域
其他工具配置、部署清单或工具目录。未知的
类源路径仍然无法通过配置检查。特定于应用程序的名称,例如
作为 src/customer.config.ts 坚持执行。
将现有配置移动到工具中
升级不会重写已提交的配置,也不会从文件中推断出一种类型
地区的名称。更改现有的加工区域 kind 从 implementation 来
tooling. 给 .github/** 它自己的工具区域,并排除 .github/** 从
任何其他匹配区域。使用 code-budget init --scope <scope> --dry-run 来
检查完整的默认值,而不替换您的策略。
对于工具目录下的产品逻辑,添加一个实现区域,例如
include: ["scripts/import-customers/**"]. 将相同的模式添加到工具中
地区的 exclude 列表。为任何测试和测试保留单独的验证规则
产品目录中的固定装置。重叠区域仍然无法通过检查。
报告包括: TOOLING (UNLIMITED) 和JSON totals.tooling,包括档案;
LOC和语言计数。工具有助于组合语言报告,
但不是实现上限或验证与实现的比率。
JSON信封仍然是版本 1.0 具有增材工装总数和种类。
详尽处理区域种类的消费者必须接受 tooling.
独立配置名称为 code-budget.config.mjs, .js, .cjs.
这个 0.0.1 budgets 模式保持可读并发出迁移诊断;
它的 maxFiles 和 maxBytes 限制是遗留的。
命令
code-budget:无需配置的推断非失败分析;check用它。code-budget report:报告配置的或推断的度量,为退出0 过剩的政策。code-budget check:要求配置;出口1表示违规,出口2表示错误。code-budget init --scope <scope>:创建config并立即检查; 支持--dry-run和--force.code-budget scopes [--details]:显示每个天花板和捆绑基准。code-budget explain <path>:显示匹配模式和执行效果。
所有命令接受 --cwd, --config, --json, --details, --no-color,
--version,以及上下文 --help. JSON只将一个版本化的信封写入
标准输出,包括使用和配置错误。
命名的天花板
| 范围 | 实现代码行 |
|---|---|
atomic-library | 1000年 |
simple-tool | 10,000 |
standalone-tool | 40000年 |
platform | 75000年 |
infrastructure | 175000年 |
suite | 350000年 |
看到 METHODOLOGY.md,或者逃跑 code-budget scopes --details,
对于绑定的固定参考基准数据集和计数边界。
库API
包导出 analyzeRepository, checkBudgets, defineConfig,配置
加载和分类帮助器、呈现帮助器以及 SCOPES /
SCOPE_NAMES 用TypeScript声明元数据。