Skip to content

Commit fc03dde

Browse files
namuitsds
authored andcommitted
Add min_subject_width to TextWidth
1 parent 49e8a66 commit fc03dde

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

config/default.yml

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ CommitMsg:
108108
enabled: true
109109
description: 'Check text width'
110110
max_subject_width: 60
111+
min_subject_width: 0
111112
max_body_width: 72
112113

113114
TrailingPeriod:

lib/overcommit/hook/commit_msg/text_width.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ def find_errors_in_subject(subject)
2121
max_subject_width =
2222
config['max_subject_width'] +
2323
special_prefix_length(subject)
24-
return unless subject.length > max_subject_width
24+
min_subject_width = config['min_subject_width']
25+
return unless subject.length > max_subject_width || subject.length < min_subject_width
2526

26-
@errors << "Please keep the subject <= #{max_subject_width} characters"
27+
@errors << "Please keep the subject <= #{max_subject_width} and >= " \
28+
"#{min_subject_width} characters"
2729
end
2830

2931
def find_errors_in_body(lines)

spec/overcommit/hook/commit_msg/text_width_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
'CommitMsg' => {
100100
'TextWidth' => {
101101
'max_subject_width' => 70,
102+
'min_subject_width' => 4,
102103
'max_body_width' => 80
103104
}
104105
}
@@ -111,6 +112,12 @@
111112
it { should warn /subject/ }
112113
end
113114

115+
context 'when subject is less than 4 characters' do
116+
let(:commit_msg) { 'A' * 3 }
117+
118+
it { should warn /subject/ }
119+
end
120+
114121
context 'when subject is 70 characters or fewer' do
115122
let(:commit_msg) { 'A' * 70 }
116123

0 commit comments

Comments
 (0)