Skip to content

Instantly share code, notes, and snippets.

@oalders
Created September 21, 2022 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oalders/9023d60a1681b265b7feafd1370f8c41 to your computer and use it in GitHub Desktop.
Save oalders/9023d60a1681b265b7feafd1370f8c41 to your computer and use it in GitHub Desktop.
Pod Spell Checking Script
#!/usr/bin/env perl
# Mostly borrowed from Code::TidyAll::Plugin::PodSpell
use 5.36.0;
use Capture::Tiny qw( capture );
use FindBin ();
use IPC::Run3 qw( run3 );
use Pod::Spell ();
my $filename = shift @ARGV;
if ( !$filename ) {
say STDERR 'No filename provided';
exit(1);
}
my ( $text, $error ) = capture {
Pod::Spell->new->parse_from_file($filename)
};
if ($error) {
say STDERR $error;
exit(1);
}
# customize with path to your stopwords file
my @cmd = ( 'ispell', '-a', '-p', "$FindBin::Bin/../../../.stopwords" );
my ($output);
try { run3( \@cmd, \$text, \$output, \$error ) }
catch ($e) {
my $msg = q{error running '} . join( q{ }, @cmd ) . q{': };
say STDERR $msg;
say STDERR $e;
exit(1);
}
my ( @errors, %seen );
for my $line ( split( m{\n}, $output ) ) {
if ( my ( $original, $remaining )
= ( $line =~ /^[\&\?\#] (\S+)\s+(.*)/ ) ) {
if ( !$seen{$original}++ ) {
my ($suggestions) = ( $remaining =~ /: (.*)/ );
if ($suggestions) {
push(
@errors,
sprintf(
'%s (suggestions: %s)', $original, $suggestions
)
);
}
else {
push( @errors, $original );
}
}
}
}
if (@errors) {
say STDERR
sprintf( "unrecognized words:\n%s", join( "\n", sort @errors ) );
exit(1);
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment