Skip to content

Commit

Permalink
chore(commitlint): adjust rules for length of commit message check (T…
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomchan-cxj authored Dec 16, 2022
1 parent 88334f1 commit 3c8909a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,29 @@ module.exports = {
],
plugins: ['commitlint-plugin-function-rules'],
rules: {
'header-max-length': [2, 'always', 72],
'function-rules/header-max-length': [
2,
'always',
(parsed) => {
const { header } = parsed;
if (!header) return [false, 'header cannot be empty'];
let prTextIndex = -1;
const regResult = /\s*\(#\w+\)$/.exec(header);
if (regResult && typeof regResult.index === 'number') {
prTextIndex = regResult.index;
console.log(`This commit message header has PR number texts at position ${prTextIndex}, which will be ignored.`);
}
let { length } = header;
if (prTextIndex !== -1) {
length = prTextIndex;
}
const maxLength = 72;
if (length <= maxLength) {
return [true];
}
return [false, `header must not be longer than ${maxLength} characters, current length is ${length}`];
},
],
'header-min-length': [0],
'function-rules/header-min-length': [
2,
Expand All @@ -39,11 +61,11 @@ module.exports = {
const { subject } = parsed;
if (!subject) return [false, 'header subject cannot be empty'];
const { length } = subject;
const minLength = 8;
const minLength = 15;
if (length >= minLength) {
return [true];
}
return [false, `header subject cannot be shorter than ${minLength} characters, current length is ${length}`];
return [false, `header subject must not be shorter than ${minLength} characters, current length is ${length}`];
},
],
'type-enum': [
Expand Down

0 comments on commit 3c8909a

Please sign in to comment.