Skip to content

Commit 51eb207

Browse files
committed
Merge branch 'issue609' of https://github.com/bentglasstube/Perl-Critic into bentglasstube-issue609
Conflicts: Changes
2 parents 6525643 + 3fb09fd commit 51eb207

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

Changes

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Revision history for Perl module Perl::Critic
22

3+
[New Policies]
4+
* Added a policy: ControlStructures::ProhibitYadaOperator - Never use ...
5+
in production code.
6+
37
[Miscellanea]
48
* Add more strict/warnings importer modules.
59

MANIFEST

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ lib/Perl/Critic/Policy/ControlStructures/ProhibitPostfixControls.pm
7878
lib/Perl/Critic/Policy/ControlStructures/ProhibitUnlessBlocks.pm
7979
lib/Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm
8080
lib/Perl/Critic/Policy/ControlStructures/ProhibitUntilBlocks.pm
81+
lib/Perl/Critic/Policy/ControlStructures/ProhibitYadaOperator.pm
8182
lib/Perl/Critic/Policy/Documentation/PodSpelling.pm
8283
lib/Perl/Critic/Policy/Documentation/RequirePackageMatchesPodName.pm
8384
lib/Perl/Critic/Policy/Documentation/RequirePodAtEnd.pm
@@ -291,6 +292,7 @@ t/ControlStructures/ProhibitPostfixControls.run
291292
t/ControlStructures/ProhibitUnlessBlocks.run
292293
t/ControlStructures/ProhibitUnreachableCode.run
293294
t/ControlStructures/ProhibitUntilBlocks.run
295+
t/ControlStructures/ProhibitYadaOperator.run
294296
t/Documentation/RequirePackageMatchesPodName.run
295297
t/Documentation/RequirePodAtEnd.run
296298
t/Documentation/RequirePodLinksIncludeText.run
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 :
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## name Basic passing
2+
## failures 0
3+
## cut
4+
5+
for (1 ... 3) {
6+
do_something();
7+
}
8+
9+
for ('a' ... 'b') {
10+
do_something();
11+
}
12+
13+
#-----------------------------------------------------------------------------
14+
15+
## name Basic failure
16+
## failures 1
17+
## cut
18+
19+
do_something();
20+
21+
...
22+
23+
do_something();
24+
25+
#-----------------------------------------------------------------------------
26+
27+
## name Excessive yadaing
28+
## failures 1
29+
## cut
30+
31+
do_something();
32+
33+
...
34+
...
35+
...
36+
...
37+
38+
do_something();
39+
40+
#-----------------------------------------------------------------------------
41+
42+
# Local Variables:
43+
# mode: cperl
44+
# cperl-indent-level: 4
45+
# fill-column: 78
46+
# indent-tabs-mode: nil
47+
# c-indentation-style: bsd
48+
# End:
49+
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :

0 commit comments

Comments
 (0)