| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators; |
|
2
|
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26638
|
use 5.010001; |
|
|
40
|
|
|
|
|
170
|
|
|
4
|
40
|
|
|
40
|
|
229
|
use strict; |
|
|
40
|
|
|
|
|
134
|
|
|
|
40
|
|
|
|
|
807
|
|
|
5
|
40
|
|
|
40
|
|
217
|
use warnings; |
|
|
40
|
|
|
|
|
96
|
|
|
|
40
|
|
|
|
|
986
|
|
|
6
|
40
|
|
|
40
|
|
211
|
use Readonly; |
|
|
40
|
|
|
|
|
87
|
|
|
|
40
|
|
|
|
|
2048
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
324
|
use Perl::Critic::Utils qw{ :severities }; |
|
|
40
|
|
|
|
|
95
|
|
|
|
40
|
|
|
|
|
2121
|
|
|
9
|
40
|
|
|
40
|
|
5164
|
use parent 'Perl::Critic::Policy'; |
|
|
40
|
|
|
|
|
102
|
|
|
|
40
|
|
|
|
|
230
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Long number not separated with underscores}; |
|
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [ 59 ]; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Readonly::Scalar my $MINIMUM_INTEGER_WITH_MULTIPLE_DIGITS => 10; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub supported_parameters { |
|
23
|
|
|
|
|
|
|
return ( |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
95
|
|
|
95
|
0
|
2134
|
name => 'min_value', |
|
26
|
|
|
|
|
|
|
description => 'The minimum absolute value to require separators in.', |
|
27
|
|
|
|
|
|
|
default_string => '10_000', |
|
28
|
|
|
|
|
|
|
behavior => 'integer', |
|
29
|
|
|
|
|
|
|
integer_minimum => $MINIMUM_INTEGER_WITH_MULTIPLE_DIGITS, |
|
30
|
|
|
|
|
|
|
}, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
109
|
|
|
109
|
1
|
471
|
sub default_severity { return $SEVERITY_LOW } |
|
35
|
84
|
|
|
84
|
1
|
382
|
sub default_themes { return qw( core pbp cosmetic ) } |
|
36
|
35
|
|
|
35
|
1
|
133
|
sub applies_to { return 'PPI::Token::Number' } |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub violates { |
|
41
|
128
|
|
|
128
|
1
|
317
|
my ( $self, $elem, undef ) = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
128
|
100
|
|
|
|
557
|
return if $elem->isa( 'PPI::Token::Number::Version' ); # GitHub #856 |
|
44
|
|
|
|
|
|
|
|
|
45
|
127
|
|
|
|
|
272
|
my $min = $self->{_min_value}; |
|
46
|
|
|
|
|
|
|
|
|
47
|
127
|
100
|
|
|
|
309
|
return if $elem !~ m{ \d{4} }xms; |
|
48
|
42
|
100
|
|
|
|
404
|
return if abs $elem->literal() < $min; |
|
49
|
|
|
|
|
|
|
|
|
50
|
35
|
|
|
|
|
860
|
return $self->violation( $DESC, $EXPL, $elem ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators - Write C< 141_234_397.0145 > instead of C< 141234397.0145 >. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AFFILIATION |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
|
69
|
|
|
|
|
|
|
distribution. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Long numbers can be difficult to read. To improve legibility, Perl |
|
75
|
|
|
|
|
|
|
allows numbers to be split into groups of digits separated by |
|
76
|
|
|
|
|
|
|
underscores. This policy requires number sequences of more than three |
|
77
|
|
|
|
|
|
|
digits to be separated. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$long_int = 123456789; #not ok |
|
80
|
|
|
|
|
|
|
$long_int = 123_456_789; #ok |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$long_float = 12345678.001; #not ok |
|
83
|
|
|
|
|
|
|
$long_float = 12_345_678.001; #ok |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The minimum absolute value of numbers that must contain separators can |
|
88
|
|
|
|
|
|
|
be configured via the C<min_value> option. The default is 10,000; |
|
89
|
|
|
|
|
|
|
thus, all numbers >= 10,000 and <= -10,000 must have separators. For |
|
90
|
|
|
|
|
|
|
example: |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
[ValuesAndExpressions::RequireNumberSeparators] |
|
93
|
|
|
|
|
|
|
min_value = 100000 # That's one-hundred-thousand! |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NOTES |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
As it is currently written, this policy only works properly with |
|
98
|
|
|
|
|
|
|
decimal (base 10) numbers. And it is obviously biased toward Western |
|
99
|
|
|
|
|
|
|
notation. I'll try and address those issues in the future. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
110
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
|
111
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Local Variables: |
|
116
|
|
|
|
|
|
|
# mode: cperl |
|
117
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
|
118
|
|
|
|
|
|
|
# fill-column: 78 |
|
119
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
|
120
|
|
|
|
|
|
|
# c-indentation-style: bsd |
|
121
|
|
|
|
|
|
|
# End: |
|
122
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |