You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lots of valid commit messages are rejected incorrectly:
Reduce duplication in codebase - this is incorrectly flagged as past tense because the word 'Reduce' contains the letters 'ed'. I presume the code is attempting to detect words ending 'ed', but the regex is matching words that contain 'ed'.
Add missing directive to foobar - this is incorrectly flagged as a gerund because the word 'missing' (which isn't a verb) ends 'ing'. Adjectives like 'missing' or nouns like 'warning' occur quite frequently in commit messages, so checking anything other than the first word in the commit produces a lot of false positives.
Fix compiler warnings in foobar - this is incorrectly flagged as a gerund because the word 'warning' contains the letters 'ing'.
The text was updated successfully, but these errors were encountered:
And I improved the regex to check only the last letters from the word and only the first word after the commit type:
// commitlint.config.tsconstConfiguration: UserConfig={
...
rules: {
...
'subject-imperative': [RuleConfigSeverity.Error,'always'],},plugins: [{rules: {// inspired by https://github.com/ngx-devs/commitlint-plugin-imperative'subject-imperative': ({subject})=>{constsubjectFirstWord=subject?.trim().split(' ')[0] ?? '';constpastTenseRegex=/\b\w+ed\b/;constgerundRegex=/((\w)*(ing))/;constpastTenseErrorMessage=`The word "${subjectFirstWord}" is in the past tense. Please use the imperative form. More info at https://github.com/ngx-devs/commitlint-plugin-imperative`;constgerundErrorMessage=`The word "${subjectFirstWord}" is in the gerund. Please use the imperative form. More info at https://github.com/ngx-devs/commitlint-plugin-imperative`;constisInPastTense=pastTenseRegex.test(subjectFirstWord);if(isInPastTense){return[false,pastTenseErrorMessage];}constisInGerund=gerundRegex.test(subjectFirstWord);if(isInGerund){return[false,gerundErrorMessage];}return[true];},},},]};exportdefaultConfiguration;
Also cleaned up the code a little bit and renamed the rule to subject-imperative.
Lots of valid commit messages are rejected incorrectly:
Reduce duplication in codebase
- this is incorrectly flagged as past tense because the word 'Reduce' contains the letters 'ed'. I presume the code is attempting to detect words ending 'ed', but the regex is matching words that contain 'ed'.Add missing directive to foobar
- this is incorrectly flagged as a gerund because the word 'missing' (which isn't a verb) ends 'ing'. Adjectives like 'missing' or nouns like 'warning' occur quite frequently in commit messages, so checking anything other than the first word in the commit produces a lot of false positives.Fix compiler warnings in foobar
- this is incorrectly flagged as a gerund because the word 'warning' contains the letters 'ing'.The text was updated successfully, but these errors were encountered: