commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

feature: add flag to enable/disable multiple-scopes (default: enabled)

Open wlc015f opened this issue 1 year ago • 13 comments

Expected Behavior

our projects previous use scope like: feat(A/B): commit msg, B is a sub scope of A.

when we update @commitlint/cli from 8.3.5 to 19.2.1 , it doesn't work well as before, because for version 19.2.1 "/" is scopes delimiter to divide input scope string into several scopes.

Current Behavior

scopeEnum would divide input scope "A/B" to scope "A" and "B" to check if input scope in commitlint config rules scope-enum, we previous config scope "A/B" can not pass isScopeInEnum check.

Steps to reproduce

  1. nodejs project with @commitlint/cli 19.2.1 and husky 9.0.11
  2. set husky hooks commit-msg npx --no -- commitlint --edit $1
  3. project commitlint.config.js is
module.exports = {
    extends: [...],
    rules: {
        "scope-empty": [2, "never"],
        "scope-enum": [2, "always", ["workload/record"]]
    }
}
  1. make some changes and commit code with message test(workload/record): test commit , then get error message below:
% git commit -m "test(workload/record): test commit" 
🔍  Finding changed files since git revision af2ddf4d.
🎯  Found 1 changed file.
✅  Everything is awesome!
⧗   input: test(workload/record): test commit
✖   scope must be one of [workload, workload/record,...] 

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

husky - commit-msg script failed (code 1)

Affected packages

  • [ ] cli
  • [X] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

set scopes delimiter as a optional config for user may solve this problem, if user do not config scopes delimiter, it will works well as before.

Context

https://github.com/conventional-changelog/commitlint/issues/701#issuecomment-2044065538

wlc015f avatar Apr 09 '24 03:04 wlc015f

Which version did you use before? Can you show some terminal output to make your issue more understandable. And update the title to describe your issue better. Thanks!

escapedcat avatar Apr 09 '24 03:04 escapedcat

Thanks for clarifying your issue!

The update from 8.3.5 to 19.2.1 has several breaking issues. #901 was added in v9 and might cause your issue.

Looking at it now it would have been good to add a flag to enable/disable on multiple scopes. Might have even been a breaking change I guess but we didn't notice.

Maybe adding such flag would help in your situation?

escapedcat avatar Apr 10 '24 03:04 escapedcat

Thanks for clarifying your issue!

The update from 8.3.5 to 19.2.1 has several breaking issues. #901 was added in v9 and might cause your issue.

Looking at it now it would have been good to add a flag to enable/disable on multiple scopes. Might have even been a breaking change I guess but we didn't notice.

Maybe adding such flag would help in your situation?

yeah, a switch flag will solve my situation.

wlc015f avatar Apr 10 '24 05:04 wlc015f

Would you be able to create a PR?

escapedcat avatar Apr 10 '24 05:04 escapedcat

Would you be able to create a PR?

I'd like to try

wlc015f avatar Apr 10 '24 05:04 wlc015f

@wlc015f I still don't grasp the issue here because you missed the "Steps to reproduce" part, can you at least attach the commitlint configuration you were using?

knocte avatar Apr 11 '24 05:04 knocte

@wlc015f I still don't grasp the issue here because you missed the "Steps to reproduce" part, can you at least attach the commitlint configuration you were using?

add the details above

wlc015f avatar Apr 11 '24 16:04 wlc015f

to Implement the feature, I have looked over the relevant code, and prefer to place the code related to parse message scopes with config under the @commitlint/parse module or into the conventional-commits-parser package, function scopeEnum should just validate the rules with input config with parsed data. i need some advice/guidance @escapedcat @knocte

wlc015f avatar Apr 11 '24 16:04 wlc015f

under the @commitlint/parse module or into the conventional-commits-parser package

Yeah, I guess you should aim at creating a PR here: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser

to Implement the feature,

BTW, if I understood this ticket correctly, this is a bug, not a feature.

knocte avatar Apr 16 '24 06:04 knocte

Yes, I guess it was a breaking change because multiple scopes were added "enabled by default", right? But it's done already... so I guess this "feature" is the best option?

escapedcat avatar Apr 16 '24 09:04 escapedcat

BTW, if I understood this ticket correctly, this is a bug, not a feature.

Yes, I guess it was a breaking change because multiple scopes were added "enabled by default", right? But it's done already... so I guess this "feature" is the best option?

I think it should be worked on as a feature.

wlc015f avatar Apr 16 '24 14:04 wlc015f

Would you be able to create a PR?

escapedcat avatar Apr 17 '24 02:04 escapedcat

Would you be able to create a PR?

I'd like to try this weekend

wlc015f avatar Apr 19 '24 05:04 wlc015f