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

filter: Statementstmt 100% 63 / 63 Branchbran 86.3% 19 / 22 Conditioncond 52.1% 12 / 23 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 78.6% 107 / 136 CC 22 SCAR 21.0
CC
22
Cov
87%
_result_fields
15.1
main
10.0
format_result
3.0
CRAP 8.2
« blib/lib/YATT/Lite/WebMVC0/DBSchema.pm ↑ Summary blib/lib/YATT/Lite/Partial/ErrorReporter.pm »
1 package YATT::Lite::CLI::Lint; sub MY () {__PACKAGE__}
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use parent qw(YATT::Lite::CLI);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use YATT::Lite::MFields qw/tap all format _inspectors/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 require File::Spec;
10 6 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 12 ▶sub main {
Subroutine main: called CC=10 SCAR=23.0
Pod undocumented
29 12 my ($self, @files) = @_;
30 12 binmode STDOUT, ':encoding(utf-8)';
31 12 binmode STDERR, ':encoding(utf-8)';
32  
33 12 ▶ $self->{all} //= 1 if $self->{tap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tap"} 1 11 12
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 12 ▶ print "1..".scalar(@files)."\n" if $self->{tap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tap"} 1 11 12
35  
36 12 my $nerror = 0;
37 12 my $i = 1;
38 12 foreach my $fn (@files) {
39 14 my $abs = YATT::Lite::Util::normalize_fs_path(File::Spec->rel2abs($fn));
40 14 my $result = $self->inspector_for($abs)->lint($abs);
41 14 ▶ if ($result->{is_success}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'is_success'}) { } 4 10 14
42 4 ▶ print "ok $i - $fn\n" if $self->{tap};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tap"} 1 3 4
43 } else {
44 10 $nerror++;
45 10 my $msg = $self->format_result($fn, $result);
46 10 ▶ if ($self->{tap}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tap'}) { } 1 9 10
47 1 print "not ok $i - $fn\n";
48 1 print map {"# $_\n"} split /\n/, $msg;
49 } else {
50 9 print STDERR $msg, "\n";
51 }
52 10 ▶ last unless $self->{all};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"all"} 7 3 10
53 }
54 7 } continue { $i++ }
55  
56 12 ▶ $nerror ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$nerror ? : 9 3 12
57 }
58  
59 10 ▶sub format_result {
Subroutine format_result: called CC=3 SCAR=11.0
Pod undocumented
60 10 my ($self, $fn, $result) = @_;
61 10 ▶ my $format = $self->{format} // 'gnu';
Condition100%2/2
$self->{"format"} // "gnu"
l!l
19
MC/DC100%1/1
$self->{"format"} // "gnu"
$self->{"format"}
Truth table100%2/2
A
A= $self->{"format"}
Aresult
11
00
62 10 ▶ 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" 10 0 10
63 or die "Unknown lint output format: $format (gnu or old)\n";
64 10 $sub->($self, $self->_result_fields($fn, $result));
65 }
66  
67 10 ▶sub _result_fields {
Subroutine _result_fields: called CC=9 SCAR=27.2
68 10 my ($self, $fn, $result) = @_;
69 10 my $diag = $result->{diagnostics};
70 10 ▶ my $file = $result->{file} // $fn;
Condition33%1/3
$result->{"file"} // $fn
l!l&&r!l&&!r
1000
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 10 ▶ ? $diag->{range}{start}{line} + 1 : '-';
Branch: 1 branch
BranchTrueFalseTotal
$diag && $diag->{'range'} && defined $diag->{'range'}{'start'}{'line'} ? : 10 0 10
Condition33%2/6
$diag and $diag->{"range"} and defined $diag->{"range"}{"start"}{"line"}
!ll&&!rl&&r
0010
$diag and $diag->{"range"}
!ll&&!rl&&r
0010
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 10 ▶ // $result->{message} // 'unknown lint failure';
Branch: 1 branch
BranchTrueFalseTotal
$diag ? : 10 0 10
Condition40%2/5
(($diag ? $diag->{"message"} : undef) // $result->{"message"}) // "unknown lint failure"
l!l
100
($diag ? $diag->{"message"} : undef) // $result->{"message"}
l!l&&r!l&&!r
1000
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 10 ▶ ($file, $line, "$msg", $result->{type} // 'error');
Condition100%2/2
$result->{"type"} // "error"
l!l
19
MC/DC100%1/1
$result->{"type"} // "error"
$result->{"type"}
Truth table100%2/2
A
A= $result->{"type"}
Aresult
11
00
77 }
78  
79 # "FILE:LINE: MESSAGE"
80 9 ▶sub format_result_gnu {
Subroutine format_result_gnu: called CC=1 SCAR=0.0
Pod undocumented
81 9 my ($self, $file, $line, $msg) = @_;
82 9 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 14 ▶sub inspector_for {
Subroutine inspector_for: called CC=3 SCAR=11.0
Pod undocumented
95 14 my ($self, $fn) = @_;
96 14 require YATT::Lite::Inspector;
97 14 require YATT::Lite::Factory;
98 14 my $dir = File::Basename::dirname($fn);
99 14 my $key = do {
100 14 ▶ if (my $script = YATT::Lite::Factory->find_factory_script($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = 'YATT::Lite::Factory'->find_factory_script($dir)) { } 11 3 14
101 11 File::Basename::dirname($script);
102 } else {
103 3 $dir;
104 }
105 };
106 14 ▶ $self->{_inspectors}{$key}
Condition66%2/3
$self->{"_inspectors"}{$key} //= "YATT::Lite::Inspector"->new("dir", $dir)
l!l&&r!l&&!r
1130
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 6 1;
« blib/lib/YATT/Lite/WebMVC0/DBSchema.pm ↑ Summary blib/lib/YATT/Lite/Partial/ErrorReporter.pm »