FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
overcommit/lib/overcommit/hook/pre_commit/flay.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
/
pre_commit
/
flay.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (43 loc) · 1.48 KB
Breadcrumbs
overcommit
/
lib
/
overcommit
/
hook
/
pre_commit
/
flay.rb
Copy path
File metadata and controls
46 lines (43 loc) · 1.48 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
# frozen_string_literal: true
module
Overcommit
::
Hook
::
PreCommit
# Runs `flay` against any modified files.
#
# @see https://github.com/seattlerb/flay
class
Flay
<
Base
# Flay prints two kinds of messages:
#
# 1) IDENTICAL code found in :defn (mass*2 = MASS)
# file_path_1.rb:LINE_1
# file_path_2.rb:LINE_2
#
# 2) Similar code found in :defn (mass = MASS)
# file_path_1.rb:LINE_1
# file_path_2.rb:LINE_2
#
def
run
command
=
[
'flay'
,
'--mass'
,
@config
[
'mass_threshold'
]
.
to_s
,
'--fuzzy'
,
@config
[
'fuzzy'
]
.
to_s
]
# Use a more liberal detection method
command
+=
[
'--liberal'
]
if
@config
[
'liberal'
]
messages
=
[
]
# Run the command for each file
applicable_files
.
each
do
|
file
|
result
=
execute
(
command
,
args
:
[
file
]
)
# flay exits non-zero both when it finds duplication (with output on
# stdout) and when it crashes internally. A crash leaves stdout empty
# and writes a backtrace to stderr, so treat that as an error instead
# of silently passing.
if
!
result
.
success?
&&
result
.
stdout
.
strip
.
empty?
return
:fail
,
result
.
stderr
end
results
=
result
.
stdout
.
split
(
"
\n
\n
"
)
results
.
shift
unless
results
.
empty?
error_message
=
results
.
join
(
"
\n
"
)
.
gsub
(
/^
\d
+
\)
\s
*/
,
''
)
message
=
Overcommit
::
Hook
::
Message
.
new
(
:error
,
nil
,
nil
,
error_message
)
messages
<<
message
end
end
messages
end
end
end
Back
|
FazBrowse Home
|
New Git URL