Conformance/Check/ClaudeSettings.pm

filter: Statementstmt 36.0% 18 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 54.5% 6 / 11 Podpod 100% 5 / 5 totaltotal 33.7% 29 / 86 CC 11 SCAR 28.5
CC
11
Cov
26%
update
42.0
check
20.0
settings
6.0
CRAP 17.3
« Conformance/Update.pm ↑ Summary Conformance/Source/Git.pm »
1 package Dist::Conformance::Check::ClaudeSettings 0.008;
2  
3 # ABSTRACT: .claude/settings.json enables the plugins of the harness
4  
5 1 ▶use 5.040;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use re '/aasx';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Mojo::Base 'Dist::Conformance::Check', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Cpanel::JSON::XS();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Dist::Conformance::Schema();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 1 my $PLUGIN_RX = qr/\A[^@\s]+@[^@\s]+\z/;
16  
17 0 ▶sub config_schema ($) {
Subroutine config_schema: not called CC=1 SCAR=6.9
Pod documented
18 return {
19 0 required => [qw{file plugins}],
20 properties => {
21 file => $Dist::Conformance::Schema::PATH,
22 plugins => { type => 'array', items => { type => 'string', pattern => "$PLUGIN_RX" } },
23 missing => { %$Dist::Conformance::Schema::STATUS, default => 'fail' },
24 },
25 };
26 }
27  
28  
29 0 ▶sub settings ( $self, $snapshot ) {
Subroutine settings: not called CC=2 SCAR=17.9
Pod documented
30 0 my $file = $self->config->{file};
31 0 ▶ my $text = $snapshot->content($file) // return undef;
Condition0%0/2
$snapshot->content($file) // (return undef)
l!l
00
MC/DC0%0/1
$snapshot->content($file) // (return undef)
$snapshot->content($file)
Truth table0%0/2
A
A= $snapshot->content($file)
Aresult
11
00
32 0 return Dist::Conformance::Schema::parse_json( $text, $file );
33 }
34  
35  
36 0 ▶sub disabled ( $self, $settings ) {
Subroutine disabled: not called CC=2 SCAR=17.9
Pod documented
37 0 ▶ my $enabled = ref $settings->{enabledPlugins} eq 'HASH' ? $settings->{enabledPlugins} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $settings->{'enabledPlugins'} eq 'HASH' ? : 0 0 0
38 0 my @disabled = grep { !$enabled->{$_} } @{ $self->config->{plugins} };
39 0 return @disabled;
40 }
41  
42  
43 0 ▶sub check ( $self, $snapshot ) {
Subroutine check: not called CC=4 SCAR=30.0
Pod documented
44 0 my ( $file, $missing ) = @{ $self->config }{qw{file missing}};
45 0 my $settings = eval { $self->settings($snapshot) };
46 0 ▶ return ( 'fail', Dist::Conformance::Schema::first_line($@) ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
47 0 ▶ return ( $missing, "$file is missing" ) if !$settings;
Branch: 1 branch
BranchTrueFalseTotal
unless $settings 0 0 0
48 0 my @disabled = $self->disabled($settings);
49 0 ▶ return ( $missing, 'does not enable ' . join ', ', @disabled ) if @disabled;
Branch: 1 branch
BranchTrueFalseTotal
if @disabled 0 0 0
50 0 return ( 'pass', 'enables ' . join ', ', @{ $self->config->{plugins} } );
51 }
52  
53  
54 0 ▶sub update ( $self, $update ) {
Subroutine update: not called CC=6 SCAR=37.4
Pod documented
55 0 my $settings = eval { $self->settings( $update->snapshot ) };
56 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
57 0 $update->by_hand( Dist::Conformance::Schema::first_line($@) . ': fix it by hand' );
58 0 return;
59 }
60 0 ▶ $settings //= {};
Condition0%0/2
$settings //= {}
l!l
00
MC/DC0%0/1
$settings //= {}
$settings
Truth table0%0/2
A
A= $settings
Aresult
11
00
61 0 my @disabled = $self->disabled($settings);
62 0 ▶ return if !@disabled;
Branch: 1 branch
BranchTrueFalseTotal
unless @disabled 0 0 0
63 0 ▶ $settings->{enabledPlugins} = {} if ref $settings->{enabledPlugins} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $settings->{"enabledPlugins"} ne "HASH" 0 0 0
64 0 for my $plugin (@disabled) { $settings->{enabledPlugins}{$plugin} = Cpanel::JSON::XS::true() }
65 0 $update->write( $self->config->{file}, Dist::Conformance::Schema::encode_json($settings) );
66 0 return;
67 }
68  
69 __END__
« Conformance/Update.pm ↑ Summary Conformance/Source/Git.pm »