feat(rules): add scope-delimiter-style
Description
This PR introduces a new rule, scope-delimiter-style, which validates that commit scopes use only the allowed delimiters. This ensures consistent behavior when custom delimiters are configured.
It also adds support for passing custom delimiters to the scope-enum and scope-case rules, allowing users to redefine how multi-segment scopes are split and validated.
The default delimiters (/, \, ,) remain unchanged unless explicitly overridden.
Documentation has been updated to reflect:
- support for object-based configuration in
scope-enumandscope-case - ability to customize delimiters
- introduction of the new
scope-delimiter-stylerule - updated Multiple Scopes section describing configurable delimiters
This brings delimiter handling across all scope-related rules to a unified and configurable model.
Motivation and Context
Resolves #701
Current scope-related rules (scope-enum, scope-case) use hardcoded delimiters to split multi-segment scopes. This makes it impossible for users to adapt commitlint to projects that use different delimiter conventions.
This PR introduces configurable delimiters and a dedicated scope-delimiter-style rule, enabling consistent validation across all scope rules. It provides a unified and flexible way to define how scopes should be parsed and validated, solving the long-standing limitation described in the linked issue.
Usage examples
// commitlint.config.js
const delimiters = ["/"];
export default {
rules: {
"scope-delimiter-style": [2, "always", delimiters],
"scope-enum": [2, "always", { scopeEnums: ["api", "core"], delimiters }],
"scope-case": [2, "always", { cases: "kebab-case", delimiters }],
};
};
echo "feat(api,cor): add new version" |Â commitlint
# â§— input: feat(api,cor): add new version
# ✖ scope must be one of [api, core] [scope-enum]
# ✖ scope delimiters must be one of [/] [scope-delimiter-style]
# ✖ found 2 problems, 0 warnings
echo "feat(api/core): add new version" |Â commitlint
# success
How Has This Been Tested?
All changes are covered by an extended test suite:
-
Updated existing tests for
scope-enumandscope-caseto ensure backward compatibility with default delimiters. -
Added new tests for object-based configuration, including custom delimiter lists and empty delimiter arrays.
-
Added a full test suite for the new
scope-delimiter-stylerule, covering:- default behavior
- custom delimiter configurations
alwaysandneverconditions- fallback to default delimiters
- handling of special characters
- non-delimiter characters such as
-and_
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Pressed the copilot review. Have a look if any of that is valid or useful, thanks!
Hey @escapedcat! Thanks a lot, some of Copilot's suggestions were pretty helpful. I've pushed the changes. Whenever you have a moment, could you take a look?
lgtm, @JounQin would you mind having a look?