App-Kritika
view release on metacpan or search on metacpan
script/kritika view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use App::Kritika;
use App::Kritika::Settings;
my $opt_diff_branch;
my $opt_diff_ref;
my $opt_diff_snapshot;
GetOptions(
'diff-branch=s' => \$opt_diff_branch,
'diff-ref=s' => \$opt_diff_ref,
'diff-snapshot=i' => \$opt_diff_snapshot,
) or die("Error in command line arguments\n");
my @files;
if ( !-t STDIN ) {
@files = map { chomp $_; $_ } <>;
}
else {
@files = @ARGV;
}
@files = grep { -f $_ } @files;
die <<"EOF" unless @files;
Usage: [--diff-ref=<reference>]
[--diff-snapshot=<snapshot-seq>]
[--diff-branch=<branch>]
<file>...
EOF
my $settings = App::Kritika::Settings->new( file => $files[0] )->settings;
my $kritika = App::Kritika->new(
%$settings,
diff_branch => $opt_diff_branch,
diff_ref => $opt_diff_ref,
diff_snapshot => $opt_diff_snapshot
);
my $issues_found = 0;
my $report = $kritika->validate(@files);
if ( $report->{success} ) {
print "No violations found\n";
exit 0;
}
else {
foreach my $file ( @{ $report->{files} } ) {
if ( $file->{success} ) {
print "$file->{path}:OK\n";
next;
}
foreach my $violation ( sort { $a->{line_no} <=> $b->{line_no} }
@{ $file->{violations} } )
{
$violation->{col_no} //= 1;
print "$file->{path}:$violation->{line_no}:$violation->{col_no}: "
. "[$violation->{profile}/$violation->{rule}] $violation->{message}\n";
}
}
exit $report->{violations_found};
}
__END__
=head1 NAME
kritika - integrate with kritika.io
=head1 SYNOPSIS
# Full file analysis
kritika lib/MyFile.pm
# Report only *new* violations
kritika --diff master lib/OtherFile.pm
kritika --diff #31 lib/OtherFile.pm
kritika --diff 451e77f3 lib/OtherFile.pm
=head1 DESCRIPTION
This command allows you to quickly analyze file using L<https://kritika.io> service. Normally C<kritika.io> analyzes
your repository after the push, but of course sometimes you would like to know if something's wrong before doing
a commit.
=head2 Git Hook Example
This is based on the shipped with C<git> pre-push hook example.
#!/bin/sh
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
( run in 1.070 second using v1.01-cache-2.11-cpan-d8267643d1d )