^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+((,|\/|\\)?\s?\w+)+\))?!?: [\S ]{1,49}[^\.]$
This regex enforces the rules for the header line of the conventional commit specification.
- Supports the standard types
- Supports the breaking changes exclamation mark notation
- Enforces using up to 50 chars for the commit description
- Enforces not ending the commit description with a dot.
- Supports optional scope(s)
- Multiple scopes can be delimited by space, comma, forward slash, or backward slash (similar to
commitlint
)
Matching examples:
ci: Most basic use case
fix(api): Valid commit with optional scope
feat!: Breaking change example
feat(scope1 scope2): Multiple space separated scopes
feat(scope1, scope2)!: Comma separated scopes with breaking change
feat(scope1,scope2): Comma separated scopes without space
fix(scope1/scope2): Fwd slash without spaces
fix(scope1\scope2): Bwd slash without spaces
Non matching examples:
fix: This description is over 50 characters loooooooooooong
fix: Ending with a dot.
fix:No spacing before description
fix!(scope): Bad breaking change placement
fix (api): Invalid space between type and scope