Skip to content

Commit

Permalink
Added Ornate double-bladed sword detection
Browse files Browse the repository at this point in the history
  • Loading branch information
lancew committed Jul 27, 2016
1 parent 320f6e0 commit 9e000e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/Perl/Critic/Policy/Perlsecret.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sub violates {
'Goatse' => \&_goatse,
'Flaming X-Wing' => \&_flaming_x_wing,
'Kite' => \&_kite,
# 'Ornate Double Edged Sword' => qr/<<m=~m>>/,
'Ornate Double Edged Sword' => \&_ornate_double_edged_sword,
# 'Flathead' => qr/-=!!|-=!/,
# 'Phillips' => qr/\+=!!|\+=!/,
# 'Torx' => qr/\*=!!|\*=!/,
Expand Down Expand Up @@ -163,4 +163,13 @@ sub _kite {
}
}

sub _ornate_double_edged_sword {
for my $child ($_[0]->children)
{
next unless $child eq '<<m';
return 1 if $child->snext_sibling eq '=~'
&& $child->snext_sibling->snext_sibling eq 'm>>';
}
}

1;
8 changes: 6 additions & 2 deletions t/20-policies.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ $code = <<'__CODE__';
__CODE__
is pcritique( 'Perlsecret', \$code ), 1, '1 x Kite';

=pod
# Ornate double-bladed sword
$code = <<'__CODE__';
<<m=~m>>
<<m=~m>>
The above should not be detected
m
;
__CODE__
is pcritique( 'Perlsecret', \$code ), 1;
is pcritique( 'Perlsecret', \$code ), 1, '1 x Ornate double-bladed sword';

=pod
# Flathead.
$code = <<'__CODE__';
$x -=!! $y
Expand Down

0 comments on commit 9e000e3

Please sign in to comment.