Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support using delimiter in scope-enum #4161

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

colinaaa
Copy link
Contributor

@colinaaa colinaaa commented Sep 27, 2024

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codesandbox-ci bot commented Sep 27, 2024

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
Copy link
Member

lgtm, thanks!

@knocte wdyt?

@knocte
Copy link
Contributor

knocte commented Sep 27, 2024

LGTM but I would prefer if the contributor:

  • Enables GitHubActions in her fork.
  • Splits this PR in 2 commits (one that adds the test and one that makes the test pass).
  • Pushes each commit one by one (so that we see the first commit failing CI).

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

@colinaaa
Copy link
Contributor Author

Hi @knocte @escapedcat, I created a PR at colinaaa#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
Copy link
Contributor

knocte commented Sep 29, 2024

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

@colinaaa
Copy link
Contributor Author

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
Copy link
Contributor Author

@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
Copy link
Member

lgtm! thanks!

@knocte
Copy link
Contributor

knocte commented Sep 29, 2024

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

@escapedcat
Copy link
Member

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: b589391

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

image

@knocte
Copy link
Contributor

knocte commented Sep 29, 2024

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
Copy link
Member

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 !

@escapedcat escapedcat merged commit f55521d into conventional-changelog:master Sep 30, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants