line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::Plicease::ProhibitLeadingZeros; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1369604
|
use strict; |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
142
|
|
4
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
75
|
|
5
|
3
|
|
|
3
|
|
62
|
use 5.008001; |
|
3
|
|
|
|
|
11
|
|
6
|
3
|
|
|
3
|
|
20
|
use Perl::Critic::Utils; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
56
|
|
7
|
3
|
|
|
3
|
|
2683
|
use base qw( Perl::Critic::Policy ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1577
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Leading zeroes are okay as the first arg to chmod, and other such reasonableness |
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $DESCRIPTION = q{Integer with leading zeros outside of chmod, mkpath}; |
14
|
|
|
|
|
|
|
my $EXPLANATION = "Only use leading zeros on numbers indicating file modes"; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
1
|
17
|
sub default_severity { $SEVERITY_MEDIUM } |
17
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { () } |
18
|
11
|
|
|
11
|
1
|
111171
|
sub applies_to { 'PPI::Token::Number' } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub violates |
21
|
|
|
|
|
|
|
{ |
22
|
17
|
|
|
17
|
1
|
338
|
my($self, $element, undef) = @_; |
23
|
|
|
|
|
|
|
|
24
|
17
|
100
|
|
|
|
54
|
return unless $element =~ m/\A [+-]? (?: 0+ _* )+ [1-9]/mx; |
25
|
7
|
100
|
|
|
|
88
|
return if $element->sprevious_sibling eq 'chmod'; |
26
|
6
|
100
|
100
|
|
|
318
|
return if (eval { $element->sprevious_sibling->sprevious_sibling->sprevious_sibling->sprevious_sibling->sprevious_sibling }||'') eq 'mkpath'; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
315
|
my $working = eval { $element->parent->parent }; |
|
5
|
|
|
|
|
25
|
|
29
|
5
|
100
|
|
|
|
45
|
if($element->parent->isa('PPI::Statement::Expression')) |
30
|
|
|
|
|
|
|
{ |
31
|
4
|
|
|
|
|
25
|
my $working = $element->parent->parent; |
32
|
4
|
|
|
|
|
24
|
while(eval { $working->isa('PPI::Structure::List') }) |
|
8
|
|
|
|
|
39
|
|
33
|
|
|
|
|
|
|
{ |
34
|
4
|
|
|
|
|
39
|
$working = $working->parent; |
35
|
|
|
|
|
|
|
} |
36
|
4
|
100
|
66
|
|
|
43
|
return if $working and ($working->children)[0] eq 'chmod'; |
37
|
3
|
50
|
33
|
|
|
67
|
return if $working and ($working->children)[-3] eq 'mkpath'; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
15
|
return $self->violation($DESCRIPTION, $EXPLANATION, $element); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=encoding UTF-8 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Perl::Critic::Policy::Plicease::ProhibitLeadingZeros - Leading zeroes are okay as the first arg to chmod, and other such reasonableness |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 0.02 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This is a stupid mistake: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $x = 1231; |
64
|
|
|
|
|
|
|
my $y = 2345; |
65
|
|
|
|
|
|
|
my $z = 0032; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This is not: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
chmod 0700, "secret_file.txt"; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Neither is this: |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use File::Path qw( mkpath ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
mkpath("/foo/bar/baz", 1, 0700); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Nor is this: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
use Path::Class qw( dir ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
dir()->mkpath(1,0700); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 CAVEATS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Because C<mkpath> is not a built in (as C<chmod> is), this policy does not differentiate between the |
86
|
|
|
|
|
|
|
C<mkpath> function provided by L<File::Path> or the C<mkpath> method provided by L<Path::Class::Dir> |
87
|
|
|
|
|
|
|
and arbitrary C<mkpath> function or methods that you or someone else might define. Also, there is |
88
|
|
|
|
|
|
|
no way to really check if the object invocant of a C<mkpath> method is really an instance of |
89
|
|
|
|
|
|
|
L<Path::Class::Dir>. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This policy is based largely on the existing in-core policy, and one in the lax bundle, but adds a |
94
|
|
|
|
|
|
|
few exceptions that I find useful. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over 4 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item L<Perl::Critic::Policy::Lax::ProhibitLeadingZeros::ExceptChmod> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Graham Ollis <plicease@cpan.org> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Graham Ollis. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
113
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |