Skip to content

Commit

Permalink
Fix the bug of scope handling for unused variables
Browse files Browse the repository at this point in the history
Fix #80
  • Loading branch information
moznion committed Feb 12, 2015
1 parent 0d6cfb0 commit ad9c546
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
7 changes: 4 additions & 3 deletions META.json
Expand Up @@ -4,7 +4,7 @@
"moznion <moznion@gmail.com>"
],
"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"
],
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -86,6 +86,7 @@
"version" : "0.11",
"x_authority" : "cpan:MOZNION",
"x_contributors" : [
"Syohei YOSHIDA <syohex@gmail.com>"
"Syohei YOSHIDA <syohex@gmail.com>",
"Tom Hukins <tom@eborcom.com>"
]
}
4 changes: 2 additions & 2 deletions lib/Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions t/Policy/Variables/prohibit_unused_variables.t
Expand Up @@ -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;

0 comments on commit ad9c546

Please sign in to comment.