Commitlint
Commitlint enforces consistent, meaningful, and machine-readable commit messages by validating them against the Conventional Commits specification. In ServerCN projects, this improves:
- Git history readability
- Automated changelog generation
- Semantic versioning workflows
- CI/CD reliability
- Team collaboration and code reviews
This component is designed for TypeScript + Express.js backends but works for any Node.js project.
Installation
Install Commitlint using the ServerCN CLI:
npx servercn-cli add tooling commitlintThis command automatically:
- Installs required Commitlint dependencies
- Creates a strongly-typed configuration file
- Prepares the project for Git hook integration
What Gets Installed
The component installs the following packages:
@commitlint/cli– The Commitlint command-line interface@commitlint/config-conventional– Standard Conventional Commit rules
It also generates a configuration file:
commitlint.config.ts– Centralized rule definition
Commitlint Configuration
Below is the default configuration provided by ServerCN, with inline explanations for clarity.
commitlint.config.ts
Conventional Commit Format
All commit messages must follow this structure:
Breakdown
- type – Nature of the change (required)
- scope – Affected module or area (optional)
- subject – Short, imperative description (required)
- body – Detailed explanation (optional)
- footer – Breaking changes or issue references (optional)
Example
Common Commit Types
feat: Introduces a new featurefix: Fixes a bugdocs: Documentation-only changesstyle: Formatting changes (no logic impact)refactor: Code restructuringtest: Adding or updating testschore: Maintenance or tooling tasksci: CI/CD configurationperf: Performance improvementsbuild: Build system or dependency changesrelease: Release preparation or versioningworkflow: GitHub Actions or workflow changessecurity: Security-related fixes
Husky Integration
Commitlint is most effective when enforced via Git hooks. ServerCN is designed to work seamlessly with Husky.
npx servercn-cli add tooling huskyThis ensures:
- Invalid commit messages are rejected immediately
- Team-wide standards are enforced automatically
- No invalid commits reach the repository
Best Practices
- Keep the subject line under 72 characters when possible
- Use the imperative mood ("add", not "added")
- Always use a scope for backend modules (e.g.
auth,user,db) - Use
BREAKING CHANGE:in the footer for API-breaking updates
Summary
The ServerCN Commitlint component provides:
- Strong commit discipline
- Clear, extensible rules
- Type-safe configuration
- CI/CD-friendly enforcement
This makes it suitable for production-grade backend systems and team-based development.
Add More Tooling
npx servercn-cli add tooling commitlint husky eslint prettier lint-staged typescript