commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

feat(rules): add scope-delimiter-style

Open what1s1ove opened this issue 2 weeks ago • 3 comments

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-enum and scope-case
  • ability to customize delimiters
  • introduction of the new scope-delimiter-style rule
  • 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-enum and scope-case to 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-style rule, covering:

    • default behavior
    • custom delimiter configurations
    • always and never conditions
    • 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.

what1s1ove avatar Dec 09 '25 17:12 what1s1ove

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.

codesandbox-ci[bot] avatar Dec 09 '25 17:12 codesandbox-ci[bot]

Pressed the copilot review. Have a look if any of that is valid or useful, thanks!

escapedcat avatar Dec 10 '25 10:12 escapedcat

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?

what1s1ove avatar Dec 11 '25 13:12 what1s1ove

lgtm, @JounQin would you mind having a look?

escapedcat avatar Dec 12 '25 13:12 escapedcat