a7945140277ad744ce528af07eebdb48682936d5
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / ValuesAndExpressions / ProhibitEmptyQuotes.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitEmptyQuotes.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $EMPTY_RX => qr{\A ["|'] \s* ['|"] \z}mx;
23 Readonly::Scalar my $DESC     => q{Quotes used with an empty string};
24 Readonly::Scalar my $EXPL     => [ 53 ];
25
26 #-----------------------------------------------------------------------------
27
28 sub supported_parameters { return ()                    }
29 sub default_severity     { return $SEVERITY_LOW         }
30 sub default_themes       { return qw(core pbp cosmetic) }
31 sub applies_to           { return 'PPI::Token::Quote'   }
32
33 #-----------------------------------------------------------------------------
34
35 sub violates {
36     my ( $self, $elem, undef ) = @_;
37     if ( $elem =~ $EMPTY_RX ) {
38         return $self->violation( $DESC, $EXPL, $elem );
39     }
40     return;    #ok!
41 }
42
43 1;
44
45 __END__
46
47 #-----------------------------------------------------------------------------
48
49 =pod
50
51 =head1 NAME
52
53 Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes - Write C<q{}> instead of C<''>.
54
55 =head1 AFFILIATION
56
57 This Policy is part of the core L<Perl::Critic> distribution.
58
59
60 =head1 DESCRIPTION
61
62 Don't use quotes for an empty string or any string that is pure whitespace.
63 Instead, use C<q{}> to improve legibility.  Better still, created named values
64 like this.  Use the C<x> operator to repeat characters.
65
66   $message = '';      #not ok
67   $message = "";      #not ok
68   $message = "     "; #not ok
69
70   $message = q{};     #better
71   $message = q{     } #better
72
73   $EMPTY = q{};
74   $message = $EMPTY;      #best
75
76   $SPACE = q{ };
77   $message = $SPACE x 5;  #best
78
79
80 =head1 CONFIGURATION
81
82 This Policy is not configurable except for the standard options.
83
84
85 =head1 SEE ALSO
86
87 L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitNoisyStrings>
88
89 =head1 AUTHOR
90
91 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
92
93 =head1 COPYRIGHT
94
95 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
96
97 This program is free software; you can redistribute it and/or modify
98 it under the same terms as Perl itself.  The full text of this license
99 can be found in the LICENSE file included with this module.
100
101 =cut
102
103 # Local Variables:
104 #   mode: cperl
105 #   cperl-indent-level: 4
106 #   fill-column: 78
107 #   indent-tabs-mode: nil
108 #   c-indentation-style: bsd
109 # End:
110 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :