Skip to content

Feature Request: Support for custom 'when' values #1003

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

Open
1 of 4 tasks
danrivett opened this issue Feb 21, 2020 · 1 comment
Open
1 of 4 tasks

Feature Request: Support for custom 'when' values #1003

danrivett opened this issue Feb 21, 2020 · 1 comment
Labels

Comments

@danrivett
Copy link

I've been working on a custom plugin with custom rules, and for some of the rules I want to apply to all commit comments, however for other rules I want to only apply for non-WIP commits. I don't believe I can currently do this on a per rule basis.

Expected Behaviour

What I would like to do is something like this (ignore rule names since they refer to custom rules I created):

{
  rules: {
    [commitlintGitHubRules.issueNumberMissing]: [2, 'never-in-non-wips'],
    [commitlintGitHubRules.issueNumberFormat]: [2, 'always'],
    [commitlintGitHubRules.issueNumberDuplicate]: [2, 'never'],

    [commitlintGitHubRules.wipAllowed]: [2, 'always'],

    [commitlintGitHubRules.subjectEmpty]: [2, 'never-in-non-wips'],
    [commitlintGitHubRules.subjectSeparator]: [2, 'always'],
    [commitlintGitHubRules.subjectCase]: [2, 'always-in-non-wips', 'sentence-case'],
    [commitlintGitHubRules.subjectFullStop]: [1, 'always-in-non-wips'],

    [commitlintGitHubRules.typeCase]: [2, 'always', 'lower-case'],
  },
};

Notice how some rules use some new when values to only apply to non-WIP commits, while others apply to all commits.

As you can see, what I would like to do is specify in my configuration always-in-non-wips or never-in-non-wips since my custom plugin identifies whether a commit is a WIP or not and if it is a WIP and the when value is one of these custom values, it just returns [true] as it skips validating the WIP commit.

If the commit isn't a WIP though, then it converts the custom when to the standard equivalent: always-in-non-wips => always; never-in-non-wips => never. It then proceeds to validate accordingly.

In the configuration example above, many of the custom rules delegate to the standard corresponding rules such as subject-case, subject-full-stop, but the custom rules short-circuit for WIP commits if the when value stipulates to only validate non-WIPs. Otherwise it delegates to the standard rules after converting the when to the corresponding standard always and never values as necessary.

Current Behaviour

This all works great with one problem I didn't anticipate - the overall commitlint linter rejects any custom when value in a configuration and so blows everything up, so I can't do this.

Not allowing individual rules to allow for more than two different rule conditions seems quite limiting, and I'm raising this Issue to get some feedback on this.

Suggestion

My suggestion would be to update the linter to avoid globally policing the allowable when values and instead delegate that to individual rules to allow each one to police which values it accepts.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Your Environment

Executable Version
commitlint --version 8.3.5
git --version 2.25.0
node --version 12.16.1
danrivett added a commit to elevai-consulting/commitlint-github that referenced this issue Feb 21, 2020
…ever-in-non-wips' to allow rules to be configured for just non-WIPs.

This new functionality currently cannot be used since commitlint prevents custom 'When' values in its top-level linter, but the work had already been done so checking this in in case in future this changes.

I created a GitHub Issue asking about that possibility: conventional-changelog/commitlint#1003.
danrivett added a commit to elevai-consulting/commitlint-github that referenced this issue Feb 22, 2020
…ever-in-non-wips' to allow rules to be configured for just non-WIPs.

This new functionality currently cannot be used since commitlint prevents custom 'When' values in its top-level linter, but the work had already been done so checking this in in case in future this changes.

I created a GitHub Issue asking about that possibility: conventional-changelog/commitlint#1003.
@danrivett
Copy link
Author

As a follow-up I just published a new commitlint plugin - commitlint-plugin-github - which was the trigger for this feature request.

Currently I've had to revert code in the plugin and globally disable certain rules from being evaluated against WIP commits since I cannot configure certain rules to apply against WIP commits, but other rules not to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants