From acc91f9db2ebc6b2ec7594ad220588c48b7253b3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Mar 2016 09:19:59 +0000 Subject: [PATCH 1/1] Bug 16003: Add exception pattern list for codespell checks The 'isnt' Test::More subroutine should not be considered as a failure by the codespell check. To avoid that this patch introduces the concept of "exception patterns" for this check. --- QohA/File.pm | 24 ++++++++++++++++++++---- t/Perl.t | 8 ++++++++ t/data/5/perl/i_dont_fail_spelling.pl | 4 ++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 t/data/5/perl/i_dont_fail_spelling.pl diff --git a/QohA/File.pm b/QohA/File.pm index 420dfbd..0b828b9 100644 --- a/QohA/File.pm +++ b/QohA/File.pm @@ -80,6 +80,9 @@ sub check_spelling { return 0 unless @$full_buf; + my @exceptions = ( + qr{isnt\(}, + ); # Encapsulate the potential errors my @errors; my @lines = split /\n/, $full_buf->[0]; @@ -88,10 +91,23 @@ sub check_spelling { # Remove filepath and line numbers # my/file/path:xxx: indentifier ==> identifier - my $re = q|^| . $self->path . q|:\d+:|; - $line =~ s|$re||; - - push @errors, $line; + my $re = q|^| . $self->path . q|:(\d+):|; + if ( $line =~ $re ) { + my $line_number = $1; + my $p = $self->path; + my $guilty_line = `sed -n '${line_number}p' $p`; + my $is_an_exception; + for my $e ( @exceptions ) { + if ( $guilty_line =~ $e ) { + $is_an_exception = 1; + last; + } + } + unless ( $is_an_exception ) { + $line =~ s|$re||; + push @errors, $line; + } + } } return @errors diff --git a/t/Perl.t b/t/Perl.t index 70d8df4..2bac98f 100644 --- a/t/Perl.t +++ b/t/Perl.t @@ -92,6 +92,7 @@ eval { our $STATUS_OK = "${GREEN}OK${END}"; my $r_v0_expected = < 1; + +isnt(1, 1, 'This is a correct spelling'); -- 2.7.0