| 1 | package Git::Hooks::RubyNoDebugger; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Git::Hooks; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | our $VERSION = '0.01'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | my $debug = qr/^[^#"'.]* (?: (?: binding\.pry | byebug | debug(?:ger)? ) [(\s@[{:] ) /x; | |||||||||
| 11 | 1 | my $extention = qr/\.(?:erb|haml|hbs|handlebars|rake|rb|ru|rhtml|slim|thor)$/; | |||||||||
| 12 | |||||||||||
| 13 | sub check_commit | ||||||||||
| 14 | 2 | ▶ | { | ||||||||
|
Subroutine
check_commit: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 15 | 2 | my $git = shift; | |||||||||
| 16 | 2 | my @files = $git->filter_files_in_index('AM'); | |||||||||
| 17 | |||||||||||
| 18 | 2 | my $success = 1; | |||||||||
| 19 | |||||||||||
| 20 | 2 | $git->nocarp; | |||||||||
| 21 | # $git->get_config; | ||||||||||
| 22 | |||||||||||
| 23 | 2 | for my $file (@files) { | |||||||||
| 24 | 2 | ▶ | next unless $file =~ /$extention/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | open my $in, '<', $file or die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | while(my $line = <$in>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 27 | ▶ | if($line =~ /$debug/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 11 | chomp $line; # TODO: fix regex, it's now dependent on the newline. | |||||||||
| 31 | 11 | $git->error(__PACKAGE__, "found debug statement '$line' in $file at line $."); | |||||||||
| 32 | |||||||||||
| 33 | 11 | $success = 0; | |||||||||
| 34 | } | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 1 | close $in; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 2 | return $success; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 1 | PRE_COMMIT \&check_commit; | |||||||||
| 44 | |||||||||||
| 45 | 1 | 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<Git::Hooks::RubyNoDebugger> 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<git config --add githooks.plugin RubyNoDebugger> | ||||||||||
| 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<binding.pry>, C<byebug>, C<debug>, C<debugger>. | ||||||||||
| 69 | |||||||||||
| 70 | =head1 AUTHOR | ||||||||||
| 71 | |||||||||||
| 72 | Skye Shaw (sshaw [AT] gmail.com) | ||||||||||
| 73 | |||||||||||
| 74 | =head1 SEE ALSO | ||||||||||
| 75 | |||||||||||
| 76 | L<Git::Hooks> | ||||||||||
| 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. | ||||||||||