blib/lib/YATT/Lite/CLI/Lint.pm

filter: Statementstmt 100% 63 / 63 Branchbran 86.3% 19 / 22 Conditioncond 47.8% 11 / 23 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 77.2% 105 / 136 CC 22 SCAR 21.6
CC
22
Cov
86%
_result_fields
17.0
main
10.0
format_result
3.0
CRAP 8.7
« blib/lib/YATT/Lite/PSGIEnv.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/DBSchema.pm »
1 package YATT::Lite::CLI::Lint; sub MY () {__PACKAGE__}
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use parent qw(YATT::Lite::CLI);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use YATT::Lite::MFields qw/tap all format _inspectors/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 require File::Spec;
10 4 require File::Basename;
11  
12 #========================================
13 # yatt.lint [--tap] [--all] [--format=gnu|old] FILE...
14 #
15 # The lint logic itself lives in YATT::Lite::Inspector::lint
16 # (LintResult, non-destructive cf_let) - the same engine the language
17 # server uses. This class only formats the results (to stderr; exit 1):
18 #
19 # --format=gnu (default) FILE:LINE: MESSAGE
20 # --format=old TYPE [[file] FILE [line] LINE]
21 # MESSAGE
22 #
23 # The old format is what elisp/yatt-lint-any-mode.el parses.
24 # --all checks every file instead of stopping at the first failure.
25 # --tap emits TAP (implies --all).
26 #========================================
27  
28 10 ▶sub main {
Subroutine main: called CC=10 SCAR=23.0
Pod undocumented
29 10 my ($self, @files) = @_;
30 10 binmode STDOUT, ':encoding(utf-8)';
31 10 binmode STDERR, ':encoding(utf-8)';
32  
33 10 ▶ $self->{all} //= 1 if $self->{tap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tap"} 1 9 10
Condition50%1/2
$self->{"all"} //= 1
l!l
01
MC/DC0%0/1
$self->{"all"} //= 1
$self->{"all"}
Truth table50%1/2
A
A= $self->{"all"}
Aresult
11
00
34 10 ▶ print "1..".scalar(@files)."\n" if $self->{tap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tap"} 1 9 10
35  
36 10 my $nerror = 0;
37 10 my $i = 1;
38 10 foreach my $fn (@files) {
39 12 my $abs = YATT::Lite::Util::normalize_fs_path(File::Spec->rel2abs($fn));
40 12 my $result = $self->inspector_for($abs)->lint($abs);
41 12 ▶ if ($result->{is_success}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'is_success'}) { } 4 8 12
42 4 ▶ print "ok $i - $fn\n" if $self->{tap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tap"} 1 3 4
43 } else {
44 8 $nerror++;
45 8 my $msg = $self->format_result($fn, $result);
46 8 ▶ if ($self->{tap}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tap'}) { } 1 7 8
47 1 print "not ok $i - $fn\n";
48 1 print map {"# $_\n"} split /\n/, $msg;
49 } else {
50 7 print STDERR $msg, "\n";
51 }
52 8 ▶ last unless $self->{all};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"all"} 5 3 8
53 }
54 7 } continue { $i++ }
55  
56 10 ▶ $nerror ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$nerror ? : 7 3 10
57 }
58  
59 8 ▶sub format_result {
Subroutine format_result: called CC=3 SCAR=11.0
Pod undocumented
60 8 my ($self, $fn, $result) = @_;
61 8 ▶ my $format = $self->{format} // 'gnu';
Condition100%2/2
$self->{"format"} // "gnu"
l!l
17
MC/DC100%1/1
$self->{"format"} // "gnu"
$self->{"format"}
Truth table100%2/2
A
A= $self->{"format"}
Aresult
11
00
62 8 ▶ my $sub = $self->can("format_result_$format")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("format_result_$format") or die "Unknown lint output format: $format (gnu or old)\n" 8 0 8
63 or die "Unknown lint output format: $format (gnu or old)\n";
64 8 $sub->($self, $self->_result_fields($fn, $result));
65 }
66  
67 8 ▶sub _result_fields {
Subroutine _result_fields: called CC=9 SCAR=28.3
68 8 my ($self, $fn, $result) = @_;
69 8 my $diag = $result->{diagnostics};
70 8 ▶ my $file = $result->{file} // $fn;
Condition33%1/3
$result->{"file"} // $fn
l!l&&r!l&&!r
800
MC/DC0%0/2
$result->{"file"} // $fn
$result->{"file"} $fn
Truth table33%1/3
A // B
A= $result->{"file"}B= $fn
ABresult
1X1
011
000
71 my $line = ($diag and $diag->{range}
72 and defined $diag->{range}{start}{line})
73 8 ▶ ? $diag->{range}{start}{line} + 1 : '-';
Branch: 1 branch
BranchTrueFalseTotal
$diag && $diag->{'range'} && defined $diag->{'range'}{'start'}{'line'} ? : 8 0 8
Condition33%2/6
$diag and $diag->{"range"} and defined $diag->{"range"}{"start"}{"line"}
!ll&&!rl&&r
008
$diag and $diag->{"range"}
!ll&&!rl&&r
008
MC/DC0%0/3
$diag and $diag->{"range"} and defined $diag->{"range"}{"start"}{"line"}
$diag $diag->{"range"} defined $diag->{"range"}{"start"}{"line"}
Truth table25%1/4
A and B and C
A= $diagB= $diag->{"range"}C= defined $diag->{"range"}{"start"}{"line"}
ABCresult
0XX0
10X0
1100
1111
74 my $msg = ($diag ? $diag->{message} : undef)
75 8 ▶ // $result->{message} // 'unknown lint failure';
Branch: 1 branch
BranchTrueFalseTotal
$diag ? : 8 0 8
Condition40%2/5
(($diag ? $diag->{"message"} : undef) // $result->{"message"}) // "unknown lint failure"
l!l
80
($diag ? $diag->{"message"} : undef) // $result->{"message"}
l!l&&r!l&&!r
800
MC/DC0%0/2
(($diag ? $diag->{"message"} : undef) // $result->{"message"}) // "unknown lint failure"
($diag ? $diag->{"message"} : undef) $result->{"message"}
Truth table33%1/3
A // B
A= ($diag ? $diag->{"message"} : undef)B= $result->{"message"}
ABresult
1X1
011
000
76 8 ▶ ($file, $line, "$msg", $result->{type} // 'error');
Condition50%1/2
$result->{"type"} // "error"
l!l
08
MC/DC0%0/1
$result->{"type"} // "error"
$result->{"type"}
Truth table50%1/2
A
A= $result->{"type"}
Aresult
11
00
77 }
78  
79 # "FILE:LINE: MESSAGE"
80 7 ▶sub format_result_gnu {
Subroutine format_result_gnu: called CC=1 SCAR=0.0
Pod undocumented
81 7 my ($self, $file, $line, $msg) = @_;
82 7 sprintf "%s:%s: %s", $file, $line, $msg;
83 }
84  
85 # "TYPE [[file] FILE [line] LINE]\n MESSAGE" - the historical
86 # format_error() shape which elisp/yatt-lint-any-mode.el parses.
87 1 ▶sub format_result_old {
Subroutine format_result_old: called CC=1 SCAR=0.0
Pod undocumented
88 1 my ($self, $file, $line, $msg, $type) = @_;
89 1 sprintf "%s [[file] %s [line] %s]\n %s", $type, $file, $line, $msg;
90 }
91  
92 # One Inspector per app root (files under the same app.psgi share one).
93 # $fn must be an absolute path.
94 12 ▶sub inspector_for {
Subroutine inspector_for: called CC=3 SCAR=11.0
Pod undocumented
95 12 my ($self, $fn) = @_;
96 12 require YATT::Lite::Inspector;
97 12 require YATT::Lite::Factory;
98 12 my $dir = File::Basename::dirname($fn);
99 12 my $key = do {
100 12 ▶ if (my $script = YATT::Lite::Factory->find_factory_script($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = 'YATT::Lite::Factory'->find_factory_script($dir)) { } 9 3 12
101 9 File::Basename::dirname($script);
102 } else {
103 3 $dir;
104 }
105 };
106 12 ▶ $self->{_inspectors}{$key}
Condition66%2/3
$self->{"_inspectors"}{$key} //= "YATT::Lite::Inspector"->new("dir", $dir)
l!l&&r!l&&!r
1110
MC/DC0%0/2
$self->{"_inspectors"}{$key} //= "YATT::Lite::Inspector"->new("dir", $dir)
$self->{"_inspectors"}{$key} "YATT::Lite::Inspector"->new("dir", $dir)
Truth table66%2/3
A //= B
A= $self->{"_inspectors"}{$key}B= "YATT::Lite::Inspector"->new("dir", $dir)
ABresult
1X1
011
000
107 //= YATT::Lite::Inspector->new(dir => $dir);
108 }
109  
110 4 1;
« blib/lib/YATT/Lite/PSGIEnv.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/DBSchema.pm »