FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
overcommit/lib/overcommit/hook/commit_msg/text_width.rb at main · sds/overcommit · GitHub
sds
/
overcommit
Public
Notifications
You must be signed in to change notification settings
Fork
285
Star
4k
Code
Issues
29
Pull requests
4
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
overcommit
/
lib
/
overcommit
/
hook
/
commit_msg
/
text_width.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (43 loc) · 1.45 KB
Breadcrumbs
overcommit
/
lib
/
overcommit
/
hook
/
commit_msg
/
text_width.rb
Copy path
File metadata and controls
56 lines (43 loc) · 1.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
module
Overcommit
::
Hook
::
CommitMsg
# Ensures the number of columns the subject and commit message lines occupy is
# under the preferred limits.
class
TextWidth
<
Base
def
run
return
:pass
if
empty_message?
@errors
=
[
]
find_errors_in_subject
(
commit_message_lines
.
first
.
chomp
)
find_errors_in_body
(
commit_message_lines
)
return
:warn
,
@errors
.
join
(
"
\n
"
)
if
@errors
.
any?
:pass
end
private
def
find_errors_in_subject
(
subject
)
max_subject_width
=
config
[
'max_subject_width'
]
+
special_prefix_length
(
subject
)
if
subject
.
length
>
max_subject_width
@errors
<<
"Commit message subject must be <=
#{
max_subject_width
}
characters"
return
end
min_subject_width
=
config
[
'min_subject_width'
]
if
subject
.
length
<
min_subject_width
@errors
<<
"Commit message subject must be >=
#{
min_subject_width
}
characters"
nil
end
end
def
find_errors_in_body
(
lines
)
return
unless
lines
.
count
>
2
max_body_width
=
config
[
'max_body_width'
]
lines
[
2
..
]
.
each_with_index
do
|
line
,
index
|
if
line
.
chomp
.
size
>
max_body_width
@errors
<<
"Line
#{
index
+
3
}
of commit message has > "
\
"
#{
max_body_width
}
characters"
end
end
end
def
special_prefix_length
(
subject
)
subject
.
match
(
/^(fixup|squash)! /
)
{
|
match
|
match
[
0
]
.
length
}
||
0
end
end
end
Back
|
FazBrowse Home
|
New Git URL