|
| 1 | +package Perl::Critic::Policy::ControlStructures::ProhibitYadaOperator; |
| 2 | + |
| 3 | +use 5.006001; |
| 4 | +use strict; |
| 5 | +use warnings; |
| 6 | +use Readonly; |
| 7 | + |
| 8 | +use Perl::Critic::Utils qw{ :characters :severities }; |
| 9 | +use base 'Perl::Critic::Policy'; |
| 10 | + |
| 11 | +our $VERSION = '1.123'; |
| 12 | + |
| 13 | +#----------------------------------------------------------------------------- |
| 14 | + |
| 15 | +Readonly::Scalar my $DESC => q{yada operator (...) used}; |
| 16 | +Readonly::Scalar my $EXPL => q{The yada operator is a placeholder for code you have not yet written.}; |
| 17 | + |
| 18 | +#----------------------------------------------------------------------------- |
| 19 | + |
| 20 | +sub supported_parameters { return () } |
| 21 | +sub default_severity { return $SEVERITY_HIGH } |
| 22 | +sub default_themes { return qw( core pbp maintenance ) } |
| 23 | +sub applies_to { return 'PPI::Token::Operator' } |
| 24 | + |
| 25 | +#----------------------------------------------------------------------------- |
| 26 | + |
| 27 | +sub violates { |
| 28 | + my ( $self, $elem, undef ) = @_; |
| 29 | + |
| 30 | + if ( _is_yada( $elem ) ) { |
| 31 | + return $self->violation( $DESC, $EXPL, $elem ); |
| 32 | + } |
| 33 | + return; #ok! |
| 34 | +} |
| 35 | + |
| 36 | +sub _is_yada { |
| 37 | + my ( $elem ) = @_; |
| 38 | + |
| 39 | + return if $elem ne '...'; |
| 40 | + #return if not defined $elem->statement; |
| 41 | + |
| 42 | + # if there is something significant on both sides of the element it's |
| 43 | + # probably the three dot range operator |
| 44 | + return if ($elem->snext_sibling and $elem->sprevious_sibling); |
| 45 | + |
| 46 | + return 1; |
| 47 | +} |
| 48 | + |
| 49 | +1; |
| 50 | + |
| 51 | +__END__ |
| 52 | +
|
| 53 | +#----------------------------------------------------------------------------- |
| 54 | +
|
| 55 | +=pod |
| 56 | +
|
| 57 | +=head1 NAME |
| 58 | +
|
| 59 | +Perl::Critic::Policy::ControlStructures::ProhibitYadaOperator - Never use C<...> in production code. |
| 60 | +
|
| 61 | +=head1 AFFILIATION |
| 62 | +
|
| 63 | +This Policy is part of the core L<Perl::Critic|Perl::Critic> |
| 64 | +distribution. |
| 65 | +
|
| 66 | +
|
| 67 | +=head1 DESCRIPTION |
| 68 | +
|
| 69 | +The yada operator C<...> is not something you'd want in production code but |
| 70 | +it is perfectly useful less critical environments. |
| 71 | +
|
| 72 | +=head1 CONFIGURATION |
| 73 | +
|
| 74 | +This Policy is not configurable except for the standard options. |
| 75 | +
|
| 76 | +
|
| 77 | +=head1 AUTHOR |
| 78 | +
|
| 79 | +Alan Berndt <alan@eatabrick.org> |
| 80 | +
|
| 81 | +=head1 COPYRIGHT |
| 82 | +
|
| 83 | +Copyright (c) 2015 Alan Berndt. All rights reserved. |
| 84 | +
|
| 85 | +This program is free software; you can redistribute it and/or modify |
| 86 | +it under the same terms as Perl itself. The full text of this license |
| 87 | +can be found in the LICENSE file included with this module. |
| 88 | +
|
| 89 | +=cut |
| 90 | +
|
| 91 | +# Local Variables: |
| 92 | +# mode: cperl |
| 93 | +# cperl-indent-level: 4 |
| 94 | +# fill-column: 78 |
| 95 | +# indent-tabs-mode: nil |
| 96 | +# c-indentation-style: bsd |
| 97 | +# End: |
| 98 | +# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |
0 commit comments