conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.93k stars 912 forks source link

feat: support using delimiter in `scope-enum` #4161

Closed colinaaa closed 2 months ago

colinaaa commented 2 months ago

Description

Currently, if the scope in message has delimiters(/, , or \), it is considered as multiple scopes and is tested separately.

I add extra checks to see if the scope matches the enum directly to allow 'scope-enum' to have delimiter.

Motivation and Context

Scope should be able to have delimiter like /. And tests should pass when 'scope-enum' is configured to have delimiter.

Usage examples

// commitlint.config.js
module.exports = {
  rules: {
    'scope-enum': [
      RuleConfigSeverity.Error,
      'always',
      [
        'foo/bar',
      ],
    ],
  },
};
echo "fix(foo/bar): qux" | commitlint # fails

⧗   input: fix(foo/bar): qux
✖   scope must be one of [foo/bar] [scope-enum]

How Has This Been Tested?

  1. A multipleSlash test case is added.
  2. Check if adding foo/bar to scope-enum would work.

Types of changes

Checklist:

codesandbox-ci[bot] commented 2 months ago

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.

escapedcat commented 2 months ago

lgtm, thanks!

@knocte wdyt?

knocte commented 2 months ago

LGTM but I would prefer if the contributor:

This way we make sure the bug is really being fixed.

colinaaa commented 2 months ago

Hi @knocte @escapedcat, I created a PR at https://github.com/colinaaa/commitlint/pull/1 to do what you said.

It shows that the tests if failing without the source code changes:

https://github.com/colinaaa/commitlint/actions/runs/11089407847/job/30810494667

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  @commitlint/rules/src/scope-enum.test.ts > Scope Enum Validation > Always > Multi-Scope Messages > Succeeds with a 'multipleSlash' message when the scopes are included in enum
AssertionError: expected false to be truthy
 ❯ @commitlint/rules/src/scope-enum.test.ts:154:20
    152|      ['bar/baz']
    153|     );
    154|     expect(actual).toBeTruthy();
       |                    ^
    155|     expect(message).toEqual('scope must be one of [bar/baz]');
    156|    });

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  @commitlint/rules/src/scope-enum.test.ts > Scope Enum Validation > Never > Messages with Scopes > Fails with a 'multipleSlash' message when the scopes are included in enum
AssertionError: expected true to be falsy

- Expected
+ Received

- true
+ false

 ❯ @commitlint/rules/src/scope-enum.test.ts:202:20
    200|      ['bar/baz']
    201|     );
    202|     expect(actual).toBeFalsy();
       |                    ^
    203|     expect(message).toEqual('scope must not be one of [bar/baz]');
    204|    });

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯

And the test passed after I made this changes:

https://github.com/colinaaa/commitlint/actions/runs/11089426928/job/30810538885?pr=1

PTAL~

knocte commented 2 months ago

Why did you create a PR on your fork? You just need to put those commits in this PR.

colinaaa commented 2 months ago

Why did you create a PR on your fork? You just need to put those commits in this PR.

Because I cannot run the action in this PR. As you can see now, GitHub says:

This workflow requires approval from a maintainer

colinaaa commented 2 months ago

@knocte Now this PR contains two commits:

  1. 25926c6 for adding tests. It fails on CI.
  2. b589391 for changing source code. It should make CI pass.
escapedcat commented 2 months ago

lgtm! thanks!

knocte commented 2 months ago

Thanks for splitting in 2 commits. The CI of your 2nd commit is red, why?

escapedcat commented 2 months ago

Thanks for splitting in 2 commits. The CI of your 2nd commit is red, why?

I think it's "a bug" in Github?

It's green here: https://github.com/conventional-changelog/commitlint/pull/4161/commits/b5893912a688a39c56f3ba0a9dfa9e24dd06e701

And here if you click the red X: https://github.com/conventional-changelog/commitlint/pull/4161/commits

image
knocte commented 2 months ago

I think it's "a bug" in Github?

We probably should only enable that step if CI is running in a repo that is not a fork, I guess.

escapedcat commented 2 months ago

We probably should only enable that step if CI is running in a repo that is not a fork, I guess.

Yeah, this is a bit confusing.

Apart from this I guess we're good here. Thanks @colinaaa !