conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.41k stars 883 forks source link

Match IDs? #95

Closed AustinMatherne closed 6 years ago

AustinMatherne commented 6 years ago

Can commitlint validate numerical IDs?

PRJ-123: valid commit
PRJ-789: valid commit
MFB-123: valid commit
MFB: invalid commit
marionebl commented 6 years ago

This feature is not implemented yet. There is a PR taking a stab at it: https://github.com/marionebl/commitlint/pull/76, where I added an outline how this could work:

// commitlint.config.js
module.exports = {
  parserPreset: './parser-preset',
  rules: {
     'references-empty': [2, 'never'],
     // extended use case, check if id is present
     'references-enum': getIssueIds().then((ids) => [2, 'always', ids])
  }
}

// parser-preset
module.exports = {
  paserOpts: {
    issuePrefixes: ['PRJ-', 'MFB-']
  }
};
marionebl commented 6 years ago

@AustinMatherne Would the feature match your use case?

AustinMatherne commented 6 years ago

@marionebl What is the value of ids? Is it a RegEx, or an array of all possible IDs?

I'm matching against thousands of numerical IDs. Generating an array of them is easy enough, but seems less than ideal.

Thanks!

marionebl commented 6 years ago

It is an string[], like the other *-enum rules. My impression is you'd be catered by this anyways as for your example the *-enum rule is not necessary:

  1. given references-empty: [2, 'never'], commits without issue id would fail as outlined in your examples
  2. optionally, given 'references-enum': [2, 'always', someArray] you could fetch the actual list of available/allowed issue ids (say by fetching them from JIRA) and check if the given ID is present. The pattern is established for the lerna and patternplate configs and works reasonably well: https://github.com/marionebl/commitlint/blob/master/%40commitlint/config-lerna-scopes/index.js#L6

I'd like to keep parsing/regexp matching out of commitlint. If the current conventional-commits-parser capabilities are not enough to distinguish between valid and invalid references we can work on improving it.

AustinMatherne commented 6 years ago

In theory validating the ID against a real Jira story would be nice, but there's no way my team would accept an online requirement in order to make commits. Instead I'd have to create an array for every value between "0" and at least "99999".

happyhunter7 commented 4 years ago

@AustinMatherne I created a plugin and a config special for JIRA commit messages style commitlint-jira ;) I think this will be useful for you :)