@elsikora/git-branch-lint
v1.2.2
Published
Lint your git branch names
Readme
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, contractsapplication- use cases and orchestration logicinfrastructure- adapters (git, config loading)presentation- CLI controllers, prompts, formatters
Features
- Template-driven branch validation using placeholders (for example
:type/:nameor: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-lintOr with other package managers:
yarn add -D @elsikora/git-branch-lint
pnpm add -D @elsikora/git-branch-lint
bun add -d @elsikora/git-branch-lintUsage
Validate current branch:
npx @elsikora/git-branch-lintStart interactive branch creation:
npx @elsikora/git-branch-lint -b
# or
npx @elsikora/git-branch-lint --branchBehavior notes:
- When
:ticketis present inbranch-pattern, both forms are valid:- with ticket:
feature/proj-123-user-authentication - without ticket:
feature/user-authentication
- with ticket:
- Interactive prompt normalizes ticket-id to lowercase before branch creation.
- Placeholder prompts are generated from
branch-patternin 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-patterndefines placeholders with:placeholdertokens.- Placeholder naming supports lowercase letters, digits, and hyphens (for example
:jira-ticket). :typeis validated against configuredbranches.branch-subject-patternsupports:string- shared regex for all non-typeplaceholders.object- regex per placeholder key (for examplescope,description,ticket).
- Optional placeholders are supported when the token is followed by
-inbranch-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
domainand are consumed viaapplicationuse cases. presentationdoes I/O only; it must not own business validation rules.infrastructurecontains adapters only; default domain rules are defined outside adapter implementation.applicationdepends 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:e2eLicense
MIT. See LICENSE.
