| 1 | package Dist::Conformance::Check::ClaudeSettings 0.004; | ||||||||||||
| 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 | 0 | ▶ | sub config_schema ($) { | ||||||||||
|
Subroutine
config_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 16 | return { | ||||||||||||
| 17 | 0 | required => [qw{file plugins}], | |||||||||||
| 18 | properties => { | ||||||||||||
| 19 | file => $Dist::Conformance::Schema::PATH, | ||||||||||||
| 20 | plugins => { type => 'array', items => { type => 'string', pattern => '\A[^@\s]+@[^@\s]+\z' } }, | ||||||||||||
| 21 | missing => { %$Dist::Conformance::Schema::STATUS, default => 'fail' }, | ||||||||||||
| 22 | }, | ||||||||||||
| 23 | }; | ||||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | |||||||||||||
| 27 | 0 | ▶ | sub settings ( $self, $snapshot ) { | ||||||||||
|
Subroutine
settings: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 28 | 0 | my $file = $self->config->{file}; | |||||||||||
| 29 | 0 | ▶ | my $text = $snapshot->content($file) // return undef; | ||||||||||
|
Condition0%0/2
$snapshot->content($file) // (return undef)
MC/DC0%0/1
$snapshot->content($file) // (return undef)
$snapshot->content($file)
Truth table0%0/2
A
A= $snapshot->content($file)
| |||||||||||||
| 30 | 0 | return Dist::Conformance::Schema::parse_json( $text, $file ); | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub disabled ( $self, $settings ) { | ||||||||||
|
Subroutine
disabled: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 35 | 0 | ▶ | my $enabled = ref $settings->{enabledPlugins} eq 'HASH' ? $settings->{enabledPlugins} : {}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | 0 | my @disabled = grep { !$enabled->{$_} } @{ $self->config->{plugins} }; | |||||||||||
| 37 | 0 | return @disabled; | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | |||||||||||||
| 41 | 0 | ▶ | sub check ( $self, $snapshot ) { | ||||||||||
|
Subroutine
check: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 42 | 0 | my ( $file, $missing ) = @{ $self->config }{qw{file missing}}; | |||||||||||
| 43 | 0 | my $settings = eval { $self->settings($snapshot) }; | |||||||||||
| 44 | 0 | ▶ | return ( 'fail', Dist::Conformance::Schema::first_line($@) ) if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | ▶ | return ( $missing, "$file is missing" ) if !$settings; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 0 | my @disabled = $self->disabled($settings); | |||||||||||
| 47 | 0 | ▶ | return ( $missing, 'does not enable ' . join ', ', @disabled ) if @disabled; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 0 | return ( 'pass', 'enables ' . join ', ', @{ $self->config->{plugins} } ); | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub update ( $self, $update ) { | ||||||||||
|
Subroutine
update: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 53 | 0 | my $settings = eval { $self->settings( $update->snapshot ) }; | |||||||||||
| 54 | 0 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 0 | $update->by_hand( Dist::Conformance::Schema::first_line($@) . ': fix it by hand' ); | |||||||||||
| 56 | 0 | return; | |||||||||||
| 57 | } | ||||||||||||
| 58 | 0 | ▶ | $settings //= {}; | ||||||||||
|
Condition0%0/2
$settings //= {}
MC/DC0%0/1
$settings //= {}
$settings
Truth table0%0/2
A
A= $settings
| |||||||||||||
| 59 | 0 | my @disabled = $self->disabled($settings); | |||||||||||
| 60 | 0 | ▶ | return if !@disabled; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 0 | ▶ | $settings->{enabledPlugins} = {} if ref $settings->{enabledPlugins} ne 'HASH'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 0 | $settings->{enabledPlugins}{$_} = Cpanel::JSON::XS::true() for @disabled; | |||||||||||
| 63 | 0 | $update->write( $self->config->{file}, Dist::Conformance::Schema::encode_json($settings) ); | |||||||||||
| 64 | 0 | return; | |||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | __END__ | ||||||||||||