App-Critique

 view release on metacpan or  search on metacpan

lib/App/Critique/Command/collect.pm  view on Meta::CPAN

    local $SIG{INT} = sub { $PAUSE_PROCESSING++ };

    my $num_processed = 0;

    my @filtered_all;
    while ( @$all ) {
        if ( $PAUSE_PROCESSING ) {
            warning('[processing paused]');

        PROMPT:
            my $continue = prompt_str(
                '>> (r)esume (h)alt (a)bort | (s)tatus ',
                {
                    valid   => sub { $_[0] =~ m/[rhas]{1}/ },
                    default => 'r',
                }
            );

            if ( $continue eq 'r' ) {
                warning('[resuming]');
                $PAUSE_PROCESSING = 0;

lib/App/Critique/Command/process.pm  view on Meta::CPAN

        # perlcritic can fail, so lets guard against it and let the user
        # decide if they want to carry on
        my @violations;
        eval {
            @violations = $self->discover_violations( $session, $file, $opt );
            1;
        } or do {
            info(HR_ERROR);
            warn($@);
            info(HR_LIGHT);
            my $should_review = prompt_yn(
                BOLD(sprintf 'A error has occurred do you want to continue?'),
                { default => 'y' }
            );
            unless ( $should_review ) { exit }
            next;
        };

        # remember it the first time we use it
        # but do not update it for each re-process
        # which we do after each edit
        $file->remember('violations' => scalar @violations)
            unless $file->recall('violations');

        if ( @violations == 0 ) {
            info(ITALIC('No violations found, proceeding to next file.'));
            next MAIN;
        }
        else {
            my $should_review = prompt_yn(
                BOLD(sprintf 'Found %d violations, would you like to review them?', (scalar @violations)),
                { default => 'y' }
            );

            if ( $should_review ) {

                my ($reviewed, $edited) = (
                    $file->recall('reviewed') // 0,
                    $file->recall('edited')   // 0,
                );

                foreach my $violation ( @violations ) {

                    $self->display_violation( $session, $file, $violation, $opt );
                    $reviewed++;

                    my $should_edit = prompt_yn(
                        BOLD('Would you like to fix this violation?'),
                        { default => 'y' }
                    );

                    my $did_commit = 0;

                    if ( $should_edit ) {
                        $did_commit = $self->edit_violation( $session, $file, $violation );
                        $edited++ if $did_commit;
                    }

lib/App/Critique/Command/process.pm  view on Meta::CPAN

        info(HR_LIGHT);
        info('%s', join "\n" => $git->RUN('diff', { 'color' => $App::Critique::CONFIG{COLOR} }));
        my $policy_name = $violation->policy;
        $policy_name =~ s/^Perl\:\:Critic\:\:Policy\:\://;

        my $commit_msg = sprintf "%s - critique(%s)" => $violation->description, $policy_name;

    CHOOSE:

        info(HR_LIGHT);
        my $commit_this_change = prompt_str(
            (
                BOLD('Commit Message:').
                "\n\n    ".(join "\n    " => split /\n/ => $commit_msg)."\n\n".
                BOLD("Press ENTER to accept this message, enter text to be appended to the commit message, or (n)o for more options.\n")
            ),
        );

        if ( !$commit_this_change ) {
            info(HR_DARK);
            info('Adding and commiting file (%s) to git', $abs_filename);

lib/App/Critique/Command/process.pm  view on Meta::CPAN


            my ($sha) = $git->rev_parse('HEAD');

            $file->remember('shas'     => [ @{ $file->recall('shas') || [] }, $sha ]);
            $file->remember('commited' => ($file->recall('commited') || 0) + 1);

            return 1;
        }
        elsif ( lc($commit_this_change) eq 'n' ) {
            info(HR_LIGHT);
            my $what_now = prompt_str(
                BOLD('What would you like to do? edit the (f)ile, edit the (c)ommit message or (a)ppend the commit message'),
                { valid => sub { $_[0] =~ m/[fca]{1}/ } }
            );

            if ( $what_now eq 'c' ) {
                info(HR_LIGHT);
                $commit_msg = prompt_str( BOLD('Please write a commit message') );
                $commit_msg =~ s/\\n/\n/g; # un-escape any newlines ...
                goto CHOOSE;
            }
            elsif ( $what_now eq 'a' ) {
                info(HR_LIGHT);
                $commit_msg .= "\n\n" . prompt_str( BOLD('Please append the commit message') );
                goto CHOOSE;
            }
            elsif ( $what_now eq 'f' ) {
                goto EDIT;
            }
        }
        else {
            $commit_msg .= "\n\n" . $commit_this_change;
            goto CHOOSE;
        }
    }
    else {
    RETRY:
        info(HR_LIGHT);
        my $what_now = prompt_str(
            BOLD('No edits found, would like to (e)dit again, (s)kip this violation or (b)lame the file?'),
            { valid => sub { $_[0] =~ m/[esb]{1}/ } }
        );

        if ( $what_now eq 'e' ) {
            goto EDIT;
        }
        elsif ( $what_now eq 's' ) {
            return 0;
        }



( run in 2.378 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )