Skip to content

feat(rules): add subject-matches & header-matches rules #819

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

Closed
wants to merge 2 commits into from
Closed

feat(rules): add subject-matches & header-matches rules #819

wants to merge 2 commits into from

Conversation

sepehr
Copy link

@sepehr sepehr commented Oct 5, 2019

Description

This brings two additional rules to the table; header-matches and subject-matches which are given a string regex to match against the header and subject respectively.

Motivation and Context

The motivation behind this is more about ease-of-use when granular customization is needed. While I'm sure, the same goal can be achieved using custom parsers, I found myself not wanting to redefine headers and subjects in parser presets. I just needed more customization power.

While this might suit a plugin, I felt like it could also be a good fit for core rules as it opens up endless possibilities for customization.

Usage examples

// commitlint.config.js
module.exports = {
 'subject-matches': [2, 'always', '^[A-Z]{1}.+\\.(\\s#\\d+)?$'],
 'header-matches': [2, 'always', '^(Feat|Bug):\\s[A-Z]{1}.+\\.(\\s#\\d+)?$']
};
echo "Header. #420" | commitlint # passes
echo "header #420" | commitlint # fails
echo "Feat: Add new rules. #819" | commitlint # passes

How Has This Been Tested?

Added new test suites.

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.

@byCedric
Copy link
Member

@marionebl what do you think? I think it definitely helps users give more customization, I'm not sure if it's "in the same vision" of the other rules. Like are we giving to much customization? Again, I don't think so but this one might be better if you decide 😄

Thanks for your work @sepehr ❤️ it looks solid!

@escapedcat
Copy link
Member

@sepehr sorry, this got lost. Would you mind rebasing it? Then we could merge it.

@escapedcat escapedcat closed this Mar 26, 2021
@sepehr
Copy link
Author

sepehr commented Mar 26, 2021

No worries @escapedcat. I'll give it a look asap.

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