[libcode-tidyall-perl] 260/374: add PodSpell

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:31 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcode-tidyall-perl.

commit ca93ea67626f96af8b20002dac34bdf84f904fcc
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Tue Sep 25 15:22:32 2012 -0700

    add PodSpell
---
 .ispell_english                       |   14 +++++
 lib/Code/TidyAll/Plugin/PodSpell.pm   |  108 +++++++++++++++++++++++++++++++++
 lib/Code/TidyAll/t/Plugin.pm          |    2 +-
 lib/Code/TidyAll/t/Plugin/PodSpell.pm |   38 ++++++++++++
 tidyall.ini                           |    4 +-
 xt/author/Plugin-PodSpell.t           |    3 +
 6 files changed, 166 insertions(+), 3 deletions(-)

diff --git a/.ispell_english b/.ispell_english
new file mode 100644
index 0000000..cb1c320
--- /dev/null
+++ b/.ispell_english
@@ -0,0 +1,14 @@
+conf
+dir
+js
+jsbeautify
+jshint
+jslint
+lib
+masontidy
+noll
+perlcritic
+perlcriticrc
+perltidy
+repos
+txn
diff --git a/lib/Code/TidyAll/Plugin/PodSpell.pm b/lib/Code/TidyAll/Plugin/PodSpell.pm
new file mode 100644
index 0000000..7a88c14
--- /dev/null
+++ b/lib/Code/TidyAll/Plugin/PodSpell.pm
@@ -0,0 +1,108 @@
+package Code::TidyAll::Plugin::PodSpell;
+use Code::TidyAll::Util qw(basename uniq);
+use Capture::Tiny qw();
+use IPC::System::Simple qw();
+use IPC::Run3;
+use Pod::Spell;
+use Moo;
+use Text::ParseWords qw(shellwords);
+extends 'Code::TidyAll::Plugin';
+
+has 'ispell_argv' => ( is => 'ro', default => sub { '' } );
+has 'ispell_cmd'  => ( is => 'ro', default => sub { 'ispell' } );
+has 'suggest'     => ( is => 'ro' );
+
+sub validate_file {
+    my ( $self, $file ) = @_;
+
+    my ( $text, $error ) = Capture::Tiny::capture { Pod::Spell->new->parse_from_file($file) };
+    die $error if $error;
+
+    my ($output);
+    my @cmd = ( $self->ispell_cmd, shellwords( $self->ispell_argv ), "-a" );
+    run3( \@cmd, \$text, \$output, \$error );
+    die $error if $error;
+
+    my ( @errors, %seen );
+    foreach my $line ( split( "\n", $output ) ) {
+        if ( my ( $original, $remaining ) = ( $line =~ /^[\&\?\#] (\S+)\s+(.*)/ ) ) {
+            if ( !$seen{$original}++ ) {
+                my ($suggestions) = ( $remaining =~ /: (.*)/ );
+                if ( $suggestions && $self->suggest ) {
+                    push( @errors, sprintf( "%s (suggestions: %s)", $original, $suggestions ) );
+                }
+                else {
+                    push( @errors, $original );
+                }
+            }
+        }
+    }
+    die sprintf( "unrecognized words:\n%s\n", join( "\n", sort @errors ) ) if @errors;
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Code::TidyAll::Plugin::PodSpell - use Pod::Spell + ispell with tidyall
+
+=head1 SYNOPSIS
+
+   In tidyall.ini:
+
+   [PodSpell]
+   select = lib/**/*.{pm,pod}
+   ispell_argv = -p $ROOT/.ispell_english
+   suggest = 1
+
+=head1 DESCRIPTION
+
+Uses L<Pod::Spell> in combination with
+L<ispell|http://fmg-www.cs.ucla.edu/geoff/ispell.html> to spell-check POD. Any
+seemingly misspelled words will be output one per line.
+
+You can specify additional valid words by:
+
+=over
+
+=item *
+
+Adding them to your personal ispell dictionary, e.g. ~/.ispell_english
+
+=item *
+
+Adding them to an ispell dictionary in the project root, then including this in
+the configuration:
+
+    ispell_argv = -p $ROOT/.ispell_english
+
+=back
+
+The dictionary file contains one word per line.
+
+=head1 INSTALLATION
+
+Install ispell from your package manager or from the link above.
+
+=head1 CONFIGURATION
+
+=over
+
+=item ispell_argv
+
+Arguments to pass to ispell. "-a" will always be passed, in order to parse the
+results.
+
+=item ispell_cmd
+
+Full path to ispell
+
+=item suggest
+
+If true, show suggestions next to misspelled words. Default is false.
+
+=back
diff --git a/lib/Code/TidyAll/t/Plugin.pm b/lib/Code/TidyAll/t/Plugin.pm
index f094522..195009c 100644
--- a/lib/Code/TidyAll/t/Plugin.pm
+++ b/lib/Code/TidyAll/t/Plugin.pm
@@ -53,7 +53,7 @@ sub tidyall {
     }
     elsif ( my $expect_error = $p{expect_error} ) {
         is( $result->state, 'error', "state=error [$desc]" );
-        like( $result->error, $expect_error, "error message [$desc]" );
+        like( $result->error || '', $expect_error, "error message [$desc]" );
     }
 }
 
diff --git a/lib/Code/TidyAll/t/Plugin/PodSpell.pm b/lib/Code/TidyAll/t/Plugin/PodSpell.pm
new file mode 100644
index 0000000..2c4ae5d
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin/PodSpell.pm
@@ -0,0 +1,38 @@
+package Code::TidyAll::t::Plugin::PodSpell;
+use Code::TidyAll::Util qw(write_file);
+use Test::Class::Most parent => 'Code::TidyAll::t::Plugin';
+
+sub test_filename { 'Foo.pod' }
+
+sub test_main : Tests {
+    my $self = shift;
+
+    my $dict_file = $self->{root_dir} . "/.ispell_english";
+
+    $self->tidyall(
+        source    => '=head SUMMARY\n\nthe quick brown fox jumped over the lazy dogs',
+        expect_ok => 1,
+        desc      => 'ok',
+    );
+    $self->tidyall(
+        source       => '=head SUMMARY\n\nthe quick browwn fox jumped over the lazeey dogs',
+        expect_error => qr/unrecognized words:\nbrowwn\nlazeey/,
+        desc         => 'spelling mistakes',
+    );
+    write_file( $dict_file, "browwn\n" );
+    $self->tidyall(
+        source       => '=head SUMMARY\n\nthe quick browwn fox jumped over the lazeey dogs',
+        conf         => { ispell_argv => "-p $dict_file" },
+        expect_error => qr/unrecognized words:\nlazeey/,
+        desc         => 'spelling mistakes, one in dictionary',
+    );
+    write_file( $dict_file, "browwn\nlazeey\n" );
+    $self->tidyall(
+        source    => '=head SUMMARY\n\nthe quick browwn fox jumped over the lazeey dogs',
+        conf      => { ispell_argv => "-p $dict_file" },
+        expect_ok => 1,
+        desc      => 'spelling mistakes, all in dictionary',
+    );
+}
+
+1;
diff --git a/tidyall.ini b/tidyall.ini
index 0f169ab..e16fd8d 100644
--- a/tidyall.ini
+++ b/tidyall.ini
@@ -7,8 +7,8 @@ select = {bin,lib}/**/{tidyall,*.{pl,pm,pod}}
 
 [PodSpell]
 select = {bin,lib}/**/{tidyall,*.{pl,pm,pod}}
-allow_words = conf jsbeautify jshint jslint masontidy perlcritic perlcriticrc perltidy dir js noll repos txn lib
-show_suggestions = 1
+ispell_argv = -p $ROOT/.ispell_english
+suggest = 1
 
 [PerlCritic]
 select = lib/**/*.pm
diff --git a/xt/author/Plugin-PodSpell.t b/xt/author/Plugin-PodSpell.t
new file mode 100644
index 0000000..faae6ee
--- /dev/null
+++ b/xt/author/Plugin-PodSpell.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Plugin::PodSpell;
+Code::TidyAll::t::Plugin::PodSpell->runtests;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git



More information about the Pkg-perl-cvs-commits mailing list