Created
September 21, 2022 20:55
-
-
Save oalders/9023d60a1681b265b7feafd1370f8c41 to your computer and use it in GitHub Desktop.
Pod Spell Checking Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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