From ad9c546fbf2476ba7e7cebafc3c34085d3452c32 Mon Sep 17 00:00:00 2001 From: moznion Date: Thu, 12 Feb 2015 16:27:24 +0900 Subject: [PATCH] Fix the bug of scope handling for unused variables Fix #80 --- META.json | 7 ++-- .../Variables/ProhibitUnusedVariables.pm | 4 +-- .../Variables/prohibit_unused_variables.t | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/META.json b/META.json index 4da21dd..73f0ffb 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ "moznion " ], "dynamic_config" : 0, - "generated_by" : "Minilla/v2.3.0, CPAN::Meta::Converter version 2.143240", + "generated_by" : "Minilla/v2.3.0, CPAN::Meta::Converter version 2.142690", "license" : [ "perl_5" ], @@ -54,7 +54,7 @@ "List::Util" : "1.41", "Module::Load" : "0", "Module::Pluggable" : "0", - "Regexp::Lexer" : "0.04", + "Regexp::Lexer" : "0.05", "String::CamelCase" : "0", "Test::Deep::NoTest" : "0", "feature" : "0", @@ -86,6 +86,7 @@ "version" : "0.11", "x_authority" : "cpan:MOZNION", "x_contributors" : [ - "Syohei YOSHIDA " + "Syohei YOSHIDA ", + "Tom Hukins " ] } diff --git a/lib/Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm b/lib/Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm index c7d887c..cf08b4d 100644 --- a/lib/Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm +++ b/lib/Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm @@ -32,12 +32,12 @@ sub evaluate { for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { $token_type = $token->{type}; - if ($token_type == LEFT_PAREN) { + if ($token_type == LEFT_BRACE) { $depth++; next; } - if ($token_type == RIGHT_PAREN) { + if ($token_type == RIGHT_BRACE) { for my $variable (keys %vars_by_depth) { push @violations, { filename => $file, diff --git a/t/Policy/Variables/prohibit_unused_variables.t b/t/Policy/Variables/prohibit_unused_variables.t index 4359262..aa64e56 100644 --- a/t/Policy/Variables/prohibit_unused_variables.t +++ b/t/Policy/Variables/prohibit_unused_variables.t @@ -167,3 +167,37 @@ my %foo; m/ (?{ $foo{bar} }) /smx; +=== +--- dscr: exist case (https://github.com/moznion/Perl-Lint/issues/80) +--- failures: 0 +--- params: +--- input +for my $num ( qw(1 2 3) ) { + print $num; +} +foreach my $num ( qw(1 2 3) ) { + print $num; +} + +=== +--- dscr: not exist case (https://github.com/moznion/Perl-Lint/issues/80) +--- failures: 2 +--- params: +--- input +for my $num ( qw(1 2 3) ) { +} +foreach my $num ( qw(1 2 3) ) { +} + +=== +--- dscr: different scope (https://github.com/moznion/Perl-Lint/issues/80) +--- failures: 2 +--- params: +--- input +for my $num ( qw(1 2 3) ) { +} +foreach my $num ( qw(1 2 3) ) { +} + +print $num; +