feat(scope): Adding Scope to Commits
Learn how to use scopes in Conventional Commits to indicate the area of the codebase affected. Covers naming conventions, common scopes, and when scopes add value.
Detailed Explanation
Using Scopes in Conventional Commits
A scope is an optional noun placed in parentheses after the commit type that describes the section of the codebase affected by the change. Scopes make commit histories more scannable and help teams quickly identify which area of the project was modified.
Format
<type>(<scope>): <description>
Example Messages
feat(auth): add two-factor authentication support
fix(api): handle timeout errors in payment endpoint
refactor(database): migrate from Sequelize to Prisma
Common Scope Naming Patterns
| Pattern | Examples |
|---|---|
| Module or package | auth, payments, notifications |
| Layer | api, ui, database, config |
| Framework area | router, middleware, store |
| Monorepo package | core, cli, web, mobile |
When to Use Scopes
Scopes are most valuable when:
- The project has clearly defined modules or packages
- Multiple developers work on different areas simultaneously
- You want to filter commit history by area (e.g.,
git log --grep="feat(auth)") - Your team has agreed on a set of valid scopes
When to Skip Scopes
Scopes can be omitted when:
- The change is cross-cutting and affects multiple areas equally
- The project is small enough that scopes add noise
- Your team has not established scope conventions
Enforcing Scopes with commitlint
You can configure commitlint to enforce a set of allowed scopes:
// commitlint.config.js
module.exports = {
rules: {
'scope-enum': [2, 'always', ['auth', 'api', 'ui', 'db', 'config']],
},
};
This prevents typos and inconsistent scope names across the team.
Use Case
Your team works on a large application with distinct modules for authentication, payments, and notifications. You have just added a new OAuth provider to the auth module and want the commit message to clearly indicate that the change is scoped to the authentication area, making it easy to filter in git log.