distrolint/Check/DeprecatedFeatures.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« distrolint/Check/VersionVar.pm ↑ Summary distrolint/Check/PostfixDeref.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2023 -- leonerd@leonerd.org.uk
5  
6 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Object::Pad 0.807;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 class App::perl::distrolint::Check::DeprecatedFeatures 0.09;
10  
11 1 ▶apply App::perl::distrolint::CheckRole::EachFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 0 ▶apply App::perl::distrolint::CheckRole::TreeSitterPerl;
Subroutine BEGIN: called CC=1 SCAR=2.6
13  
14 use Text::Treesitter 0.07; # child_by_field_name
15  
16 use constant DESC => "check that no perl file uses any deprecated features";
17 use constant SORT => 16;
18  
19 =head1 NAME
20  
21 C<App::perl::distrolint::Check::DeprecatedFeatures> - check C<use feature> statements
22  
23 =head1 DESCRIPTION
24  
25 =for highlighter
26  
27 This checks C<use feature ...> statements looking for deprecated features.
28  
29 The following named features are deprecated, and not allowed:
30  
31 switch
32  
33 =cut
34  
35 method run ( $app )
36 {
37 return $self->run_for_each_perl_file( check_file => );
38 }
39  
40 my %BANNED_FEATURES = map { $_ => 1 } qw(
41 switch
42 );
43  
44 my $QUERY = <<'EOF';
45 (use_statement
46 module: _ @module (#eq? @module "feature"))
47 @statement
48 EOF
49  
50 method check_file ( $file )
51 {
52 my $tree = $self->parse_perl_file( $file );
53  
54 return 0 unless $self->walk_each_query_match( $QUERY, $tree->root_node, method ( $captures ) {
55 my $node = $captures->{statement};
56 my @imports = $self->extract_use_module_imports( $node );
57  
58 foreach my $feature ( @imports ) {
59 $BANNED_FEATURES{$feature} and
60 App->diag( App->format_file( $file, $node->start_row + 1 ), " uses feature ", App->format_literal( $feature ) ),
61 return 0
62 }
63  
64 return 1;
65 } );
66  
67 return 1;
68 }
69  
70 =head1 AUTHOR
71  
72 Paul Evans <leonerd@leonerd.org.uk>
73  
74 =cut
75  
76 0x55AA;
« distrolint/Check/VersionVar.pm ↑ Summary distrolint/Check/PostfixDeref.pm »