Debian Codegraph @

build-aux/scripts/check-perlcritic-config

raw
1 #! /usr/bin/perl
2 # Written by Zack Weinberg <zackw at panix.com> in 2021.
3 # To the extent possible under law, Zack Weinberg has waived all
4 # copyright and related or neighboring rights to this work.
5 #
6 # See https://creativecommons.org/publicdomain/zero/1.0/ for further
7 # details.
8
9 # Compare the set of available Perl::Critic policies with the set of
10 # policies mentioned in .perlcriticrc. Fail the build if there are
11 # available policies that are not mentioned, or mentioned policies
12 # that are not available. This ensures that we always have the
13 # expected set of policies available when running perlcritic, and
14 # that we have thought about whether each one _should_ be enabled.
15 # ("Mentioned" does not mean "enabled". [-APolicy::WeDontWantToUse]
16 # counts as mentioning the policy for purpose of this script.)
17
18 # Ideally this would be a perlcritic policy itself, so it would get
19 # run on any invocation of perlcritic, not just on 'make distcheck'.
20
21 use v5.14; # implicit use strict, use feature ':5.14'
22 use warnings FATAL => 'all';
23 use utf8;
24 use open qw(:std :utf8);
25 no if $] >= 5.022, warnings => 'experimental::re_strict';
26 use if $] >= 5.022, re => 'strict';
27
28 use Perl::Critic ();
29 use Perl::Critic::UserProfile ();
30
31 sub all_policies {
32 return
33 map { ("$_" => 1) }
34 Perl::Critic->new(-profile => q(), -severity => 1)->policies();
35 }
36
37 sub mentioned_policies {
38 return
39 map { (s/^Perl::Critic::Policy:://r => 1) }
40 Perl::Critic::UserProfile->new()->listed_policies();
41 }
42
43 sub compare_mentioned_to_all {
44 my %all = all_policies();
45 my %mentioned = mentioned_policies();
46
47 my @unmentioned;
48 for my $p (keys %all) {
49 push @unmentioned, $p unless exists $mentioned{$p};
50 }
51
52 my @uninstalled;
53 for my $p (keys %mentioned) {
54 push @uninstalled, $p unless exists $all{$p};
55 }
56
57 my $fail = 0;
58 if (@unmentioned) {
59 print {*STDERR}
60 "*** Unmentioned policies:\n\t",
61 join("\n\t", sort @unmentioned),
62 "\n\n";
63 $fail = 1;
64 }
65 if (@uninstalled) {
66 print {*STDERR}
67 "*** Uninstalled policies:\n\t",
68 join("\n\t", sort @uninstalled),
69 "\n\n";
70 $fail = 1;
71 }
72
73 return $fail;
74 }
75
76 exit compare_mentioned_to_all();