Skip to content

Commit

Permalink
Merge pull request #536 from imanoleguskiza/532-disable-max-subject-w…
Browse files Browse the repository at this point in the history
…idth

Issue #532: Allow to set max_subject_width and max_body_width to 0
  • Loading branch information
veewee authored Aug 31, 2018
2 parents fdfd668 + d77baa8 commit f234b88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions doc/tasks/git_commit_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ Ensures that the commit message subject line is followed by a blank line.
*Default: 72*
Preferred limit on the commit message body lines.
Preferred limit on the commit message body lines. Set to 0 to disable the check.
**max_subject_width**
*Default: 60*
Preferred limit on the commit message subject line.
Preferred limit on the commit message subject line. Set to 0 to disable the check.
**matchers**
Expand Down
24 changes: 14 additions & 10 deletions src/Task/Git/CommitMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,23 @@ private function enforceTextWidth(ContextInterface $context)
$lines = $this->getCommitMessageLinesWithoutComments($commitMessage);

$subject = rtrim($lines[0]);
$maxSubjectWidth = $config['max_subject_width'] + $this->getSpecialPrefixLength($subject);
if ($config['max_subject_width'] > 0) {
$maxSubjectWidth = $config['max_subject_width'] + $this->getSpecialPrefixLength($subject);

if (mb_strlen($subject) > $maxSubjectWidth) {
$errors[] = sprintf('Please keep the subject <= %u characters.', $maxSubjectWidth);
if (mb_strlen($subject) > $maxSubjectWidth) {
$errors[] = sprintf('Please keep the subject <= %u characters.', $maxSubjectWidth);
}
}

foreach (array_slice($lines, 2) as $index => $line) {
if (mb_strlen(rtrim($line)) > $config['max_body_width']) {
$errors[] = sprintf(
'Line %u of commit message has > %u characters.',
$index + 3,
$config['max_body_width']
);
if ($config['max_body_width'] > 0) {
foreach (array_slice($lines, 2) as $index => $line) {
if (mb_strlen(rtrim($line)) > $config['max_body_width']) {
$errors[] = sprintf(
'Line %u of commit message has > %u characters.',
$index + 3,
$config['max_body_width']
);
}
}
}

Expand Down

0 comments on commit f234b88

Please sign in to comment.