Skip to content

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

Closed
sepehr wants to merge 2 commits intoconventional-changelog:masterfrom
sepehr:header-subject-matches
Closed

feat(rules): add subject-matches & header-matches rules#819
sepehr wants to merge 2 commits intoconventional-changelog:masterfrom
sepehr:header-subject-matches

Conversation

@sepehr
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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