line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Hooks::RubyNoDebugger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
35886
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
853
|
use Git::Hooks; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $debug = qr/^[^#"'.]* (?: (?: binding\.pry | byebug | debug(?:ger)? ) [(\s@[{:] ) /x; |
11
|
|
|
|
|
|
|
my $extention = qr/\.(?:erb|haml|hbs|handlebars|rake|rb|ru|rhtml|slim|thor)$/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub check_commit |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
my $git = shift; |
16
|
|
|
|
|
|
|
my @files = $git->filter_files_in_index('AM'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $success = 1; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$git->nocarp; |
21
|
|
|
|
|
|
|
# $git->get_config; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
for my $file (@files) { |
24
|
|
|
|
|
|
|
next unless $file =~ /$extention/; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
open my $in, '<', $file or die $!; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
while(my $line = <$in>) { |
29
|
|
|
|
|
|
|
if($line =~ /$debug/) { |
30
|
|
|
|
|
|
|
chomp $line; # TODO: fix regex, it's now dependent on the newline. |
31
|
|
|
|
|
|
|
$git->error(__PACKAGE__, "found debug statement '$line' in $file at line $."); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$success = 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
close $in; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $success; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
PRE_COMMIT \&check_commit; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Git::Hooks::RubyNoDebugger - Git::Hooks plugin that checks for calls to a Ruby debugger |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
C adds a pre-commit hook that looks for the invocation of a debugger. |
56
|
|
|
|
|
|
|
If one is detected the commit will be aborted. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 Setup |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
C |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 File Extensions |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Files with the following extensions are checked: erb, haml, hbs, handlebars, rake, rb, ru, rhtml, slim, thor |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 Debugger Calls |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The following debugger calls are checked: C, C, C, C. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Skye Shaw (sshaw [AT] gmail.com) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SEE ALSO |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 COPYRIGHT |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Copyright (c) 2015 Skye Shaw. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |