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

Fix/3779: Adjust logic for 'never' scope-enum validation #3795

Merged
merged 11 commits into from Dec 9, 2023

Conversation

joberstein
Copy link
Contributor

@joberstein joberstein commented Nov 22, 2023

Motivation and Context

Resolves issue #3779 - see for more context

Usage examples

/* commitlint.config.js */

// Commit message scopes, if present, must be one of the scopes in 'scope-enum'.
export default {
    rules: {
        "scope-enum": [2, "always", [
            "action",
            "test",
        ]]
    },
};
echo "feat(action): some message" | commitlint # passes
echo "feat(test): some message" | commitlint # passes
echo "feat(action, test): some message" | commitlint # passes
echo "feat(other, test): some message" | commitlint # fails
echo "feat(other): some message" | commitlint # fails
// Commit message scopes cannot include any of the scopes in 'scope-enum'.
export default {
    rules: {
        "scope-enum": [2, "never", [
            "action",
            "test",
        ]]
    },
};
echo "feat(action): some message" | commitlint # fails
echo "feat(test): some message" | commitlint # fails
echo "feat(action, test): some message" | commitlint # fails
echo "feat(other, test): some message" | commitlint # fails
echo "feat(other): some message" | commitlint # passes

How Has This Been Tested?

  • Added more automated tests in addition to the ones that already exist (originally 18, now 36)
  • Did manual testing with linked repo in separate test repo (npm i --no-save <path-to-dev-repo)

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.

@@ -1,139 +1,183 @@
import parse from '@commitlint/parse';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a lot of changes, but in summary, I organized the old tests by use-case and they are still getting executed; in addition, I added more automated tests to cover all of the message types for the following cases for both always and never:

  • Enum is empty (always passes for both always and never)
  • Messages without scopes (always passes for both always and never)
  • Always - messages with one or multiple scopes
  • Never - messages with scopes

@escapedcat
Copy link
Member

escapedcat commented Nov 22, 2023

/cc @karl-run maybe can have a look as well

Thanks @joberstein ! Without people like you projects like commitlint couldn't continue.

when = 'always',
value = []
) => {
if (!parsed.scope) {
if (!scope || !value.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value.length check was further down before; I can't reason out a case where "scopeEnum(..., 'never', [])" should fail, which was the original behavior, but just wanted to call this out.

value.length === 0 ||
scopeSegments.every((scope) => ensure.enum(scope, value));
if (when === 'never') {
isValid = !messageScopes.some(isScopeInEnum);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main logic change, essentially from "!messageScopes.every(isScopeInEnum)"

@escapedcat escapedcat merged commit 6fe168e into conventional-changelog:master Dec 9, 2023
4 checks passed
@escapedcat
Copy link
Member

Thanks @joberstein !

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.

None yet

2 participants