File Coverage

blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitNoisyQuotes.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 4 50.0
condition 3 9 33.3
subroutine 11 11 100.0
pod 4 5 80.0
total 46 55 83.6


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ValuesAndExpressions::ProhibitNoisyQuotes;
2              
3 40     40   25845 use 5.010001;
  40         153  
4 40     40   254 use strict;
  40         95  
  40         796  
5 40     40   296 use warnings;
  40         84  
  40         963  
6 40     40   212 use Readonly;
  40         98  
  40         2014  
7              
8 40     40   301 use Perl::Critic::Utils qw{ :severities };
  40         109  
  40         2061  
9 40     40   5029 use parent 'Perl::Critic::Policy';
  40         106  
  40         232  
10              
11             our $VERSION = '1.150';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $NOISE_RX => qr{\A ["'] [^ \w () {} [\] <> ]{1,2} ['"] \z}xms;
16             Readonly::Scalar my $DESC => q{Quotes used with a noisy string};
17             Readonly::Scalar my $EXPL => [ 53 ];
18              
19             #-----------------------------------------------------------------------------
20              
21 89     89 0 1682 sub supported_parameters { return () }
22 105     105 1 442 sub default_severity { return $SEVERITY_LOW }
23 84     84 1 384 sub default_themes { return qw(core pbp cosmetic) }
24 30     30 1 105 sub applies_to { return qw(PPI::Token::Quote::Double
25             PPI::Token::Quote::Single) }
26              
27             #-----------------------------------------------------------------------------
28              
29             sub violates {
30 72     72 1 190 my ( $self, $elem, undef ) = @_;
31 72 100       325 return if $elem !~ $NOISE_RX;
32 31         331 my $statement = $elem->statement;
33 31 0 33     701 return if $statement
      33        
      33        
34             && $statement->isa('PPI::Statement::Include')
35             && $statement->type eq 'use'
36             && $statement->module eq 'overload';
37 31         105 return $self->violation( $DESC, $EXPL, $elem );
38             }
39              
40             1;
41              
42             __END__
43              
44             #-----------------------------------------------------------------------------
45              
46             =pod
47              
48             =head1 NAME
49              
50             Perl::Critic::Policy::ValuesAndExpressions::ProhibitNoisyQuotes - Use C<q{}> or C<qq{}> instead of quotes for awkward-looking strings.
51              
52              
53             =head1 AFFILIATION
54              
55             This Policy is part of the core L<Perl::Critic|Perl::Critic>
56             distribution.
57              
58              
59             =head1 DESCRIPTION
60              
61             Don't use quotes for one or two-character strings of non-alphanumeric
62             characters (i.e. noise). These tend to be hard to read. For
63             legibility, use C<q{}> or a named value. However, braces,
64             parentheses and brackets tend to look better in quotes, so those
65             are allowed.
66              
67             $str = join ',', @list; #not ok
68             $str = join ",", @list; #not ok
69             $str = join q{,}, @list; #better
70              
71             $COMMA = q{,};
72             $str = join $COMMA, @list; #best
73              
74             $lbrace = '('; #ok
75             $rbrace = ')'; #ok
76             print '(', @list, ')'; #ok
77              
78              
79             =head1 CONFIGURATION
80              
81             This Policy is not configurable except for the standard options.
82              
83              
84             =head1 SEE ALSO
85              
86             L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes|Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes>
87              
88              
89             =head1 AUTHOR
90              
91             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
92              
93              
94             =head1 COPYRIGHT
95              
96             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
97              
98             This program is free software; you can redistribute it and/or modify
99             it under the same terms as Perl itself. The full text of this license
100             can be found in the LICENSE file included with this module.
101              
102             =cut
103              
104             # Local Variables:
105             # mode: cperl
106             # cperl-indent-level: 4
107             # fill-column: 78
108             # indent-tabs-mode: nil
109             # c-indentation-style: bsd
110             # End:
111             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :