@elsikora/git-branch-lint

中文文档
1.2.2发布于 2026/02/18MITTypeScriptES Module近 30 天下载 1.4万

点入您 git 分支名称

中文使用文档
文档目录13 节
  1. 目录
  2. 说明
  3. 特征
  4. 安装
  5. 使用量
  6. 配置
  7. Java 脚本示例
  8. 高级占位符示例
  9. 类型脚本示例
  10. package.json 示例
  11. 清洁建筑规则
  12. 发展
  13. 许可证

project-logo

吉特- 布兰克- 林特

用于一致,可执行的 Git 分支命名的 CLI 工具.

目录

说明

@elsikora/git-branch-lint 对照团队规则验证分支名称,并包括交互式分支创建流.

该项目采用分层清洁建筑:

  • domain - 商业规则、实体、政策、合同
  • application - 使用案例和管弦逻辑
  • infrastructure - 适配器(git,配置装入)
  • presentation - CLI控制器、提示器、格式化器

特征

  • 使用占位符进行模板驱动的分支验证(例如) :type/:name 或者说 :scope/:type/:description) (中文(简体) ).
  • 带有图案的可选票号支持 :type/:ticket-:name (线程部分可以省略).
  • 交互式分支创建命令( I)-b 编号 : --branch直接取自已配置的占位符.
  • 分支限制:被禁名,分/最大长度,被禁名.
  • 帮助 CLI 错误/ 提示格式化 .
  • 基于Cosmiconfig的配置发现.

安装

安装为 dev 依赖 :

npm install --save-dev @elsikora/git-branch-lint

或其他软件包管理器:

yarn add -D @elsikora/git-branch-lint
pnpm add -D @elsikora/git-branch-lint
bun add -d @elsikora/git-branch-lint

使用量

验证当前分支 :

npx @elsikora/git-branch-lint

启动交互式分支创建 :

npx @elsikora/git-branch-lint -b
# or
npx @elsikora/git-branch-lint --branch

行为说明:

  • 何时 :ticket 存在于 branch-pattern,这两个表格都是有效的:
    • 随票: feature/proj-123-user-authentication
    • 无票: feature/user-authentication
  • 交互快取在分支创建前将出票标识规范为小写 .
  • 占位符提示来自 branch-pattern 依所宣说之序.
  • 验证和分支创建使用相同的模板/模式规则.

配置

配置通过 cosmiconfig (例如 package.json, (中文(简体) ), .elsikora/git-branch-lint.config.js, (中文(简体) ), .elsikora/git-branch-lint.config.ts) (中文(简体) ).

规则语义 :

  • branch-pattern 定义占位符 :placeholder 标志.
  • 占位符命名支持小写字母、数字和连字符(例如) :jira-ticket) (中文(简体) ).
  • :type 对照配置验证 branches。 。 。 .
  • branch-subject-pattern 支持:
    • string - 对所有非 --type 占位符 .
    • object - 每个占位键的正则x(例如) scope, (中文(简体) ), description, (中文(简体) ), ticket) (中文(简体) ).
  • 可选占位符在符号后面被支持 - 内 branch-pattern (例如 :ticket-) (中文(简体) ).
  • 在分支创建前,最终组装名称再次被验证,并有完整的林特规则.

Java 脚本示例

export default {
    branches: {
        feature: { title: "Feature", description: "New functionality" },
        bugfix: { title: "Bugfix", description: "Bug fixes" },
        hotfix: { title: "Hotfix", description: "Urgent fixes" },
    },
    ignore: ["dev"],
    rules: {
        "branch-pattern": ":type/:ticket-:name",
        "branch-subject-pattern": "[a-z0-9-]+",
        "branch-prohibited": ["main", "master", "release"],
        "branch-min-length": 5,
        "branch-max-length": 50,
    },
};

高级占位符示例

export default {
    branches: ["feat", "fix", "chore"],
    rules: {
        "branch-pattern": ":scope/:type/:description",
        "branch-subject-pattern": {
            scope: "(web|api|shared)",
            description: "[a-z0-9-]+",
        },
    },
};

有效的分支示例 : web/feat/shopping-cart。 。 。 .

类型脚本示例

import type { IBranchLintConfig } from "@elsikora/git-branch-lint";

const config: IBranchLintConfig = {
    branches: {
        feature: { title: "Feature", description: "New functionality" },
        bugfix: { title: "Bugfix", description: "Bug fixes" },
        hotfix: { title: "Hotfix", description: "Urgent fixes" },
    },
    ignore: ["dev"],
    rules: {
        "branch-pattern": ":type/:ticket-:name",
        "branch-subject-pattern": "[a-z0-9-]+",
        "branch-prohibited": ["main", "master", "release"],
        "branch-min-length": 5,
        "branch-max-length": 50,
    },
};

export default config;

package.json 示例

{
    "elsikora": {
        "git-branch-lint": {
            "branches": ["feature", "bugfix", "hotfix"],
            "rules": {
                "branch-pattern": ":type/:ticket-:name",
                "branch-subject-pattern": "[a-z0-9-]+",
                "branch-prohibited": ["main", "master", "release"]
            }
        }
    }
}

清洁建筑规则

此代码库中执行的仓库标准 :

  • 商业规则 domain 并且通过 application 使用大小写.
  • presentation 它不能拥有商业验证规则.
  • infrastructure 只包含适配器;默认域规则在适配器执行之外被定义.
  • application 取决于域合同,而不是具体基础设施类别.
  • 类型/界面被取入专用类型/界面文件,以便可重复使用.
  • 进口订单和班级成员订单是强制性的,必须始终如一.

发展

常见脚本 :

npm run lint
npm run lint:types
npm run test:unit
npm run test:e2e

许可证

麻省理工学院. 见 LICENSE。 。 。 .

版本与发布记录

@elsikora/git-branch-lint 共发布 18 个版本,首次发布于 2025/03/03;过去 12 个月发布了 8 个版本。

版本发布日期距今
1.2.2latest2026/02/188 个月前
1.2.2-dev.1beta2026/02/188 个月前
1.2.12026/02/168 个月前
1.2.1-dev.12026/02/168 个月前
1.1.3-dev.22026/02/168 个月前
1.2.02026/02/148 个月前

关于 @elsikora/git-branch-lint 的常见问题

@elsikora/git-branch-lint 是什么?

点入您 git 分支名称

如何安装 @elsikora/git-branch-lint?

在项目目录运行 npm install @elsikora/git-branch-lint,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 git-branch-lint,可以用 npx git-branch-lint 直接运行。

@elsikora/git-branch-lint 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elsikora/git-branch-lint 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@elsikora/git-branch-lint 可以商用吗?

@elsikora/git-branch-lint 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@elsikora/git-branch-lint 的下载量有多少?

根据 npm 官方下载统计,@elsikora/git-branch-lint 在 2026/10/14 – 2026/11/12 这 30 天内被下载 13,865 次,日均约 462 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elsikora/git-branch-lint 还在维护吗?

最新版本 1.2.2 发布于 2026/02/18(8 个月前);至今共发布 18 个版本,其中过去 12 个月发布了 8 个;首次发布于 2025/03/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。