@elsikora/git-branch-lint

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

Lint your git branch names

原始使用文档
文档目录13 节
  1. Table Of Contents
  2. Description
  3. Features
  4. Installation
  5. Usage
  6. Configuration
  7. JavaScript Example
  8. Advanced Placeholder Example
  9. TypeScript Example
  10. package.json Example
  11. Clean Architecture Rules
  12. Development
  13. License

project-logo

Git-Branch-Lint

CLI tool for consistent, enforceable Git branch naming.

Table Of Contents

Description

@elsikora/git-branch-lint validates branch names against team rules and includes an interactive branch-creation flow.

The project follows layered clean architecture:

  • domain - business rules, entities, policies, contracts
  • application - use cases and orchestration logic
  • infrastructure - adapters (git, config loading)
  • presentation - CLI controllers, prompts, formatters

Features

  • Template-driven branch validation using placeholders (for example :type/:name or :scope/:type/:description).
  • Optional ticket-id support with pattern :type/:ticket-:name (ticket part can be omitted).
  • Interactive branch creation command (-b / --branch) built directly from configured placeholders.
  • Branch constraints: prohibited names, min/max length, subject regex.
  • Helpful CLI error/hint formatting.
  • Cosmiconfig-based configuration discovery.

Installation

Install as a dev dependency:

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

Or with other package managers:

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

Usage

Validate current branch:

npx @elsikora/git-branch-lint

Start interactive branch creation:

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

Behavior notes:

  • When :ticket is present in branch-pattern, both forms are valid:
    • with ticket: feature/proj-123-user-authentication
    • without ticket: feature/user-authentication
  • Interactive prompt normalizes ticket-id to lowercase before branch creation.
  • Placeholder prompts are generated from branch-pattern in declared order.
  • Validation and branch creation use the same template/pattern rules.

Configuration

Configuration is loaded via cosmiconfig (for example package.json, .elsikora/git-branch-lint.config.js, .elsikora/git-branch-lint.config.ts).

Rule semantics:

  • branch-pattern defines placeholders with :placeholder tokens.
  • Placeholder naming supports lowercase letters, digits, and hyphens (for example :jira-ticket).
  • :type is validated against configured branches.
  • branch-subject-pattern supports:
    • string - shared regex for all non-type placeholders.
    • object - regex per placeholder key (for example scope, description, ticket).
  • Optional placeholders are supported when the token is followed by - in branch-pattern (for example :ticket-).
  • Before branch creation, the final assembled name is validated again with full lint rules.

JavaScript Example

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,
    },
};

Advanced Placeholder Example

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

Valid branch example: web/feat/shopping-cart.

TypeScript Example

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 Example

{
    "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"]
            }
        }
    }
}

Clean Architecture Rules

Repository standards enforced in this codebase:

  • Business rules live in domain and are consumed via application use cases.
  • presentation does I/O only; it must not own business validation rules.
  • infrastructure contains adapters only; default domain rules are defined outside adapter implementation.
  • application depends on domain contracts, not concrete infrastructure classes.
  • Types/interfaces are extracted into dedicated type/interface files for reusable contracts.
  • Import order and class member ordering are lint-enforced and must remain consistent.

Development

Common scripts:

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

License

MIT. See 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 是什么?

Lint your git branch names

如何安装 @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 和提交记录判断。